### Sunday, June 11, 2017

## Change the Computer name in Ubuntu 16.04

Open terminal and run command:

`$ sudo gedit /etc/hostname `

/etc/hostname is a simple one line file, change the name to whatever your want.

Next, Open terminal and run command:

In /etc/hosts change the name in second line and make it SAME to the name in /etc/hostname.

Save your changes and restart your machine.

Next, Open terminal and run command:

`$ sudo gedit /etc/hosts `

In /etc/hosts change the name in second line and make it SAME to the name in /etc/hostname.

Save your changes and restart your machine.

### Friday, January 1, 2016

## C program to check whether a number is an Armstrong number

```
/* Also known as narcissistic numbers,
* Armstrong numbers are the sum of their own digits
* to the power of the number of digits.
* Example: 407 = 4^3 + 0^3 + 7^3 = 407
*/
#include <stdio.h>
#include <math.h>
int main(void) {
int number_to_check = 153;
int copy_number = number_to_check;
int digits[10];
int i = 0, sum = 0, number_of_digits;
while(number_to_check!=0){
digits[i] = number_to_check % 10;
number_to_check = number_to_check/10;
i++;
}
number_of_digits = i;
for(i = number_of_digits-1; i >= 0; i--){
sum = sum + pow(digits[i], number_of_digits);
}
if(copy_number == sum)
printf("The supplied number is an armstrong number.");
else
printf("The supplied number is NOT an armstrong number.");
return 0;
}
```

## C programs related to Fibonacci series

C program to find Fibonacci series without recursion

#include <stdio.h> int main(void) { int n = 10; // print n fibonacci series int a = 0, b = 1, s; printf("%d %d ", a,b); n = n - 2; // already 2 numbers printed while(n--){ s = a + b; printf("%d ",a+b); a = b; b = s; } return 0; }

### Thursday, December 31, 2015

## C program to add 2 numbers without using arithmetic operators

#include <stdio.h> int main(void) { int a = 3, b = 5, c = 0; while(b != 0){ c = a & b; // carry a = a ^ b; b = c << 1; } printf("%d",a); return 0; }

Ref: http://www.geeksforgeeks.org/add-two-numbers-without-using-arithmetic-operators/

## C program to print various patterns

**C program to print the below pattern**

ABCDEDCBA

ABCDCBA

ABCBA

ABA

A

ABCDCBA

ABCBA

ABA

A

### Wednesday, December 30, 2015

## C program to round numbers and decimals without using in-built functions

Suppose we want to round off 838.274. Depending on which place value we're rounding to, the final result can vary. For example,

Reference : http://www.calculatorsoup.com/calculators/math/roundingnumbers.php

- Round to the nearest hundred (
**8**38.274) is 800 - Round to the nearest ten (8
**3**8.274) is 840 - Round to the nearest one (83
**8**.274) is 838 - Round to the nearest tenth (838.
**2**74) is 838.3 - Round to the nearest hundredth (838.2
**7**4) is 838.27

Reference : http://www.calculatorsoup.com/calculators/math/roundingnumbers.php

**C Program to round a number to the nearest thousand**#include <stdio.h> int main(void) { double a=3250; int x = (a+500)/1000; x = x*1000; printf("%d",x); //3000 return 0; }

## C Program to swap two numbers without using a temporary variable

C Program to swap two numbers without using a temporary variable

**First Method**#include <stdio.h> int main(void) { int a=3,b=6; a = a + b; // a = 9 b = a - b; // b = 3 a = a - b; // a = 6 printf("a=%d,b=%d",a,b); return 0; }

Subscribe to:
Posts (Atom)