Skip to main content

Posts

Showing posts from September, 2017

C programs QnA

Q. If sum of two integer is 14 and if one of them is 8 then find other integer. Ans: Well, this is very simple. Simply, one integer is 8 and sum of two integers is 14. So, we need to subtract the number 8 from their sum of 14 to get the second number. So, the second number is: 14 - 8 = 6 C-Program of this task Code---> #include<stdio.h> int main () { int num1 = 8 , num2 , sum = 14 ; num2 = sum - num1 ; printf ( "The second number is: %d" , num2 ); return 0 ; }

C program to check a number is Palindrome or not

In this C -program we will check the number is Palindrome or not. The number will be taken from the user. input: The number(i.e : 567,610,7899 etc.) output: The number will be Palindrome or not CODE----> #include<stdio.h> int main () { int b , a = 0 , r = 0 , n ; printf ( " Please,Enter a number : " ); scanf ( "%d" ,& n ); b = n ; while ( n != 0 ) { r = n % 10 ; a = a * 10 + r ; n = n / 10 ; } if ( b == a ) printf ( "\n %d is a Palindrome number." , b ); else printf ( "\n %d is not a Palindrome number." , b ); return 0 ; } Download the C-Program file of this Program. Don't just read, run on your pc !!! RESULT : Please,Enter a number : 121 121 is a Palindrome number. -------------------------------- Process exited after 3.219 seconds with return value 0 Press any key to continue . . . Please,Enter a number : 122 122 is not a Palindrome number. -----------------...

C program to REVERSE a number

In this C -program we will reverse the number. The number will be taken from the user. input: The number(i.e : 567,610,7899 etc.) output: The reversed number of the given number CODE----> #include<stdio.h> int main () { long long int a = 0 , r = 0 , n ; printf ( " Please,Enter a number : " ); scanf ( "%lld" ,& n ); while ( n != 0 ) { r = n % 10 ; a = a * 10 + r ; n = n / 10 ; } printf ( "\n The reversed number is : %lld" , a ); return 0 ; } Download the C-Program file of this Program. Don't just read, run on your pc !!! RESULT : Please,Enter a number : 123456789 The reversed number is : 987654321 -------------------------------- Process exited after 5.203 seconds with return value 0 Press any key to continue . . . Images for better understanding :

C program for FIBONACCI series

In this C -program we will print the Fibonacci Series upto a range. The range will be taken from the user. input: The range(i.e : 5,6,9 etc.) output: The fibonacci series upto the given range CODE----> #include<stdio.h> int main () { int a , b , c , n ; printf ( " Enter 1st and 2nd term : " ); scanf ( "%d%d" ,& a ,& b ); printf ( " \n Enter the range : " ); scanf ( "%d" ,& n ); printf ( " \n The Fibonacci series is... \n" ); printf ( " %d %d" , a , b ); c = a + b ; while ( c <= n ) { printf ( " %d" , c ); a = b ; b = c ; c = a + b ; } return 0 ; } Download the C-Program file of this Program. Don't just read, run on your pc !!! RESULT : Enter 1st and 2nd term : 0 1 Enter the range : 100 The Fibonacci series is... 0 1 1 2 3 5 8 13 21 34 55 89 -------------------------------- Process exited after 8.411 seconds with return value 0 Pre...

Prime number or not ? in C language

In this C -program we will check a number is Prime or not. The number will be taken from the user. input: The number(i.e : 5,6,9 etc.) output: The number will be Prime or not CODE----> #include<stdio.h> int main () { int i , n , f = 0 ; printf ( "Please,Enter a positive number: " ); scanf ( "%d" ,& n ); if ( n == 0 || n == 1 ) { if ( n == 0 ) printf ( "You entered ZERO.\n0 is not a Prime number or not a Composite number.\n" ); else printf ( "You entered ONE.\n1 is not a Prime number or not a Composite number.\n" ); } else { for ( i = 1 ; i <= n ; i ++) { if ( n % i == 0 ) f = f + 1 ; } if ( f == 2 ) printf ( "%d is a Prime number.\n" , n ); else printf ( "%d is not a Prime number.\n" , n ); } return 0 ; } Download the C-Program file of this Program. Don't just read, run on your pc !!! RESULT : Please,Enter a positive ...

C program of factorial of a number

In this C -program we will calculate the factorial of a number. The number will be taken from the user. input: The number(i.e : 5,6,9 etc.) output: The factorial of the given number CODE----> #include<stdio.h> int main () { int i , n , fact = 1 ; printf ( "Enter a number: " ); scanf ( "%d" ,& n ); if ( n < 0 ) { printf ( "\n%d is a negative number. Factorial of a negative number doesn't exist." , n ); } if ( n == 0 ) { printf ( "\nThe factorial of 0 is = 0" ); } if ( n > 0 ) { for ( i = 1 ; i <= n ; i ++) { fact = fact * i ; } printf ( "\nThe factorial of %d is = %d" , n , fact ); } return 0 ; } Download the C-Program file of this Program. Don't just read, run on your pc !!! RESULT : Enter a number: 5 The factorial of 5 is = 120 -------------------------------- Process exited after 3.431 seconds with return value 0 Press a...