Posts

Showing posts from August 26, 2012

Sum the Series

Write a C program to Calculate the below Series. The Value of x and n must take from input terminal.  1.    Sum = x + x 2 + x 3 +…. +  x n   2.   Sum = x + 2x + 3x +…. +  nx  3.   Sum=x 1 + x 1/2 + x 1/3   + ….  +  x 1/n 1. #include main() { int x, n, I, sum=0, y; scanf("%d %d", &x, &n); y=x; for(I=1;I<=n;I++) { if(I==1) { printf("\n%d+", x); } else if(I==n) { printf("%d^%d = ", x, n); } else { printf("%d^%d+", x, I); } sum+=y; y=y*x; } printf("%d", sum); getch(); return 0; } 2.                                                                                                                                                                    #include main() { int x, n, I, sum=0; scanf("%d %d", &x, &n); for(I=1;I<=n;I++) { if(I==1) { printf("\n%d+", x); } else if(I==n) { printf("%dx%d = ", n, x); } else { printf(&q

Perfect Number

1. Write a C program to Print 1st 30 Perfect numbers starting from 0 main() { long  i, sum=0, j, count=0; for(j=1; ;j++) { for(i=1; i<=j/2 ; i++) { if( j%i = =0) { sum += i; } } if(j = =sum) { printf("%d ", j); count + + ; } if(count = =30) { break; } sum=0; } getch(); return 0; } << Go to Index Page >>

Reverse an Integer Number

1. Write a C program to reverse an Integer number. After print the output, make the sum of all digits. Sample Input: Enter Number: 571 Output:  After Reverse: 175 Sum of all Digits: 13 Source:                                                                                                                                                              main() { int num, i, sum=0; scanf("%d", &num); printf("After Reverse: "); while(num!= 0) {   i = num%10;   num /=10;   sum += i;   printf("%d", i); } printf("\n\nSum of all Digits: %d", sum); getch(); return 0; } << Go to Index Page >>

Palindrom

1 . Write a C program to check a Given Number, Whether  is it Palindrome or Not ? Sample Input: Enter Number: 123 Output: It is not Palindrome Sample Input: Enter Number: 121 Output: It is  Palindrome 2. Write a C program to Check a String, Whether is it Palindrome or Not ? Sample Input: Enter String: madam Output: It is  Palindrome Sample Input: Enter String: asian Output: It is not Palindrome 1.                                                                                                                                                                 main() { int num, i, rev=0, temp; printf("Enter Number: "); scanf("%d", &num); temp=num; while(temp!=0) {   i = temp%10;   rev = rev*10+i ;   temp /= 10; } if(num = =rev)   {     printf("It is a Palindrome.\n");   }     else   {     printf("It is not a Palindrome.\n");   } getc

Manipulate Series

1. Write a C program to print a Series of Integer Numbers,which is divisible by 3 from a given set of limits. Sample Input:  Start_value: 1 End_value: 10 Sample Output: 3, 6, 9 2. Write a C program to print a Series of Odd Numbers and Even Numbers. After Print Make an Average of all Printed Odd Numbers and Even Numbers. Sample Output: The Even Numbers are: 2, 4, 6, 8, 10 The Odd Numbers are: 1, 3, 5, 7, 9 The Average of Even Numbers: 6 1.                                                                                                                                                                   main() { int start, end, i ; printf("Start_Value: "); scanf("%d", &start); printf("End_Value: "); scanf("%d", &end); printf("\n\n"); for(i=start ; i <= end ; i++) { if(i%3 = = 0) printf("%d, ", i ); } getch(); return 0; } 2.                                                     

Strange Number

1. Write a C program to Print the Strange Numbers Between 1 and 100000. main() { int a, b, c, n, temp, J; printf("The Strange Numbers are:\n\t\t"); for(a=1;a<=100000;a++) { c=1; for(b=2;b<=a/2;b++) { if(a%b==0) { c=0; break; } } if(c==1) { temp=a; while(temp>0) //starting the loop for extract the number { J=temp%10; n=1; for(b=2;b<=J/2;b++) //loop for checking the digit whether is it prime or not. { if(J%b = =0) { n=0; break;  //skip the 'for loop' } } if((n= =0)||(J= =0)) { n=0; break; //skip the 'while loop' } temp /=10; }  //loop for extract finish if(n= =1) { printf("\t%d", a); } } } getch(); return 0; } << Go to Index Page >>

Prime Number Manipulation

1. Write a C program to calculate the SUM and COUNT of Primes from a given range of numbers. Formatting required for the Input and Output statements. Sample Input: Range Start From: 1 End of Range: 10 Sample Output: The Sum of Primes is: 11 Total Primes: 5 2. Write a C Program to Print all the Prime Numbers between 1 and 100.  Sample Output: 1,  2,  3,  5,  7,  11,  13,  . . . . etc 3. WAP Program to get a r ange from user and give a list of prime numbers up to that numb er . And check whe ther the sum of all printed prime numbers are equal to the given input or not ? Sample Input: 10 Sample Output: Prime list: 1, 2, 3, 5, 7 The sum is: 18 The sum is not equal to 10 1.                                                                                                                                                                  main() { int a, b, c, n=0, start, end, sum=0; printf("Range Start From: "); scanf("%d&qu