GeekInterview.com
Series: Subject: Topic:
Question: 325 of 828

Tricky C Program questions

1)Write a C program to find a peculiar two digit number which is three times the sum of its digits.

2) Bacteria are known to multiply very rapidly. If a certain container contains just one bacterium on the first day and there are twice as many on the next day. In this manner the number of bacteria in the container doubles itself everyday. Assuming that the container would be full on the 10th day with 13,312 bacteria, find the number of bacteria that was initially in the container on the first day.

3) Calculate the factorial of a number recursively. From that calculate the value of COS(X) = 1 - X2/2! + X4 /4! - X6/ 6! +…….

4) A number of “Cats” got together and decided to kill between them 999919 mice. Every cat killed equal number of “mice”. Write a program to find number of cats.

5) Consider the following number 45*45=2025; 20+25=45.Write a program to generate number between 32 and 99 that satisfies the above property.

6) Rita has a money pouch containing Rs.700. There are equal number of 25 paise coins, 50 paise and one rupee coins. Write a C program to find how many of each are there?

7) Calculate the factorial of a number recursively and from that calculate the value of ex=1+ (X1/1!) + (X2 /2!) + (X3/3!) + ……….

8) There are some goats and ducks in a farm. There are 60 eyes and 86 foot in total. Write a program to find number of goats and ducks in the farm.

9) Write a C program to find a three digit number which is greater than the aggregate of its third, tenth and the twelfth parts by 58.

10) Write a C program to find a two digit number, the second digit of which is smaller than its first digit by 4, and if the number was divided by the digit’s sum, the quotient would be 7.
Asked by: ganesan81 | Member Since May-2007 | Asked on: Jun 5th, 2007

View all questions by ganesan81

Showing Answers 1 - 40 of 40 Answers
BECKONLAND2004

Answered On : May 27th, 2008

View all answers by BECKONLAND2004

Write a C-COde to blink the character

Yes  1 User has rated as useful.
  
Login to rate this answer.
ravikth

Answered On : Oct 31st, 2008

View all answers by ravikth

Step1: We have to check the condition xy==3(x+y) -> xy/3 = x+y
The above statements unveil two essential points to write efficient program
1. x and y must be int value, not a real (float) value. so the xy will be
divisible by 3.
2. Maximum value of 3(x+y) is 54 if xy equals to 99 (max value of two digit).
so the xy will be less than 54.
Conclusion: we can get the result by checking the numbers which are divisible
by 3 and less than 54 instead of checking all the numbers.
Ans: 27

Yes  3 Users have rated as useful.
  
Login to rate this answer.
shreekanthss

Answered On : Feb 2nd, 2009

View all answers by shreekanthss

1  #include<stdio.h>    #include<math.h>    main(){   int x,y,r,m;   printf("enter a numbern");   scanf("%d",&x);   y=x%10;    x=x/10;   r=x+y;   m=3*r;   printf("%d",m);   getch();}

Yes  1 User has rated as useful.
  
Login to rate this answer.
RamLaw

Answered On : Jun 16th, 2009

View all answers by RamLaw

Answer for Q:5#include<stdio.h>int main(){ int i = 32, n = 99, sq, val1, val2, val3;  while(i <= n){  sq = i * i;  val1 = sq/100;  val2 = sq%100;    val3 = val1 + val2;    if(val3 == i){  printf("%d satisfy propertyn",i);  }   i++; } return 0;}

Yes  1 User has rated as useful.
  
Login to rate this answer.
milan.kadivar

Answered On : Jun 16th, 2009

View all answers by milan.kadivar

#include <stdio.h>#include <conio.h>void main(){ int i,x,y; clrscr(); for(i=10;i<100;i++)  {    x=i/10;    y=i%10;    if(((x+y)*3)==i)         printf("Peculiar Num is : %d",i);  }  getch();}

Yes  2 Users have rated as useful.
  
Login to rate this answer.
jothejo2

Answered On : Jun 26th, 2009

View all answers by jothejo2

Q1.This is what i've done but dere are still some bugs will fix them later But this is the whole idea.#include<stdio.h>int main(){      for (i=10;i<=99;i++)      {              j=i;   //to do the splitting of the two digit value and find the sum of its digits             while(j != 0)               {    x = j%10;                    y = y +x;                   j = j/10;                } // Because of the relation x +y = xy/3         c = i/3;         if (c == y)           printf("Perculia vlue:  %d",i);           //break;          }}

Yes  1 User has rated as useful.
  
Login to rate this answer.
ranjini.np

Answered On : Aug 6th, 2009

View all answers by ranjini.np

/* Q1: Write a C program to find a peculiar two digit number which is three times the sum of its digits.*/#include <stdio.h>int main(){    char num;    char second_pos, first_pos, total;    for(num = 10; num < 100; num++)    {            second_pos = num / 10;            first_pos = num % 10 ;            total = second_pos + first_pos;            printf("total = %d n", total);            printf(" %d n", (total * 3 ));            if(num == (3 * total))            {                printf("%d is the answern", num);                return 0;            }    }    return 0;}

  
Login to rate this answer.
npoojasjce

Answered On : Oct 13th, 2009

View all answers by npoojasjce

#include<stdio.h>void main(){   int i,a,b,sum;   for(i=10;i<100;i++)    {        a=i/10;        b=i%10;       sum=a+b;       if(b==(a-4) && (i/sum)==7)          printf("%dn",i);     }}

  
Login to rate this answer.
meenu1992

Answered On : Oct 23rd, 2009

View all answers by meenu1992

5) Consider the following number 45*45=2025; 20+25=45.Write a program to generate number between 32 and 99 that satisfies the above property.#include<stdio.h>#include<conio.h>void main(){int i,n,a,b;for(i=32;i<=99;i++){n=i*i;a=n%100;n=n100;b=a+n;{if(b==i)printf("%dt",b);}}getch();}

Yes  1 User has rated as useful.
  
Login to rate this answer.

void main() { int i,x,y; clrscr(); for(i=10;i<100;i++) { x=i/10; y=i%10; if(((x+y)*3)==i) printf("Peculiar Num is : %d",i); } getch(); }

  
Login to rate this answer.
Ankur1989

Answered On : Jan 22nd, 2010

View all answers by Ankur1989

#include<stdio.h>#include<conio.h>void main(){ clrscr();  int n, x,y,z;  printf("nEnter the number:");  scanf("%d",&n);  x=n%10;  y=n/10;  z=x+y;  if(n==3*z){  printf("nnThis is required number ...."); }   elseprintf(""nnEnter Some other number");}

  
Login to rate this answer.
Ankur1989

Answered On : Jan 22nd, 2010

View all answers by Ankur1989

//Program for numbert being three times its digits#include<stdio.h>#include<conio.h> void main(){clrscr();   int n, x,y,z; printf("nEnter the number you want to check for");  scanf("%d",&n); y=n%10; x=n/10; z=x+y; if(n==3*z){ printf("nThe number is three times some of its digits....");} else printf("nnEnter some other number"); }

  
Login to rate this answer.
Ankur1989

Answered On : Jan 22nd, 2010

View all answers by Ankur1989

//Program to calculate bacteria on first day when bacteria on 10th day is 13, 312 #include<stdio.h>#include<conio.h>  void main(){  clrscr(); int n, i,x, printf("nEnter the number of days:"); scanf("%d",&n); n=10; printf("nEnter the bacteria's at end of 10th day...:"); scanf("%d",&total); total=13,312; printf("nSo total bacteria's initially are.....:"); x=total/pow(2,n-1); } 

  
Login to rate this answer.
Ankur1989

Answered On : Jan 22nd, 2010

View all answers by Ankur1989

#include<stdio.h>#include<conio.h>#include<math.h>  void main(){clrscr(); int n, sum,x; float result;     void main() printf("nEnter the number upto which prog is to be calculated :"); scanf("%d",&n); int rec(int n){ if(n==1)  return 1;  else  return (n)*(n-1);} printf("nEnter the value of X:"); scanf("%d",&x); sum= 0; sum+=pow(x,2*(n-1))*pow(-1,n); result= sum/rec(n); printf("nnThe result is...:%f" result); }

  
Login to rate this answer.
dn007

Answered On : Jan 27th, 2010

View all answers by dn007

If (3(x+y)=10x+y= no. is 27(Answer: 27=3(2+7))

  
Login to rate this answer.
vkscool

Answered On : Sep 19th, 2010

View all answers by vkscool

Programe to fine no where secound no is less then first by 4 and the no is divided by the sum of digit of the no then the quotient is 7#include<stdio.h>#include<conio.h>void main(){ int num=20,i,j,k,l,m=0,arr[20]; while(num<100) {   j=num%10;   k=num/10;   if(k-j==4)     {       l=j+k;       printf("n%d",num);       if((num/l)==7)         {           arr[m]=num;           m++;         }     }     num++; } for(i=0;i<m;i++) {  printf("n:- %d",arr[i]); } getch(); }

  
Login to rate this answer.

Q.2.#include<stdio.h>#include<conio.h>int main(){int i,day,bact;clrscr();printf("Enter the no. of day and the total no. of bacterian");scanf("%d %d",&day,&bact);for(i=day;i>1;i--)b=b/2;printf("Number of bacteria present in the 1st day is=%dn",bact);getch();return 0;}

  
Login to rate this answer.

Q.1.#include<stdio.h>#include<conio.h>int main(){int i,x,y;clrscr();for(i=10;i<100;i++){x=i%10;y=i/10;if(i==3*(x+y))printf("%dt",i);}getch();return 0;}

  
Login to rate this answer.

Q.5.#include<stdio.h>#include<conio.h>int main(){int i,p,x,y;clrscr();for(i=32;i<=99;i++){p=i*i;x=p%100;y=p/100;if(i==(x+y))printf("%dt",i);}getch();return 0;}

  
Login to rate this answer.

Q.6. #include<stdio.h>#include<conio.h>int main(){float r;int x;clrscr();printf("Enter the Rs.n");scanf("%f",&r);x=r*4/7;printf("If there r equal no. of 25 paise coins, 50 paise coins and one rupee coins, then the no of each coins is %d n",x);getch();return 0;}

  
Login to rate this answer.

Q.8.#include<stdio.h>#include<conio.h>int main(){int x,y,p,q;clrscr();printf("Enter the no of eyes and foot in totaln");scanf("%d %d",&p,&q);x=(q-p)/2;y=(p-2*x)/2;printf("The no of goats in the farm is = %dn",x);printf("The no of ducks in the farm is = %dn",y);getch();return 0;}//The equations are//1. 2*(x+y)=p;//2. 4*x + 2*y=q;

  
Login to rate this answer.

Q.10.#include<stdio.h>#include<conio.h>int main(){int i,a,b;clrscr();for(i=10;i<100;i++){b=i%10;a=i/10;if(((a-b)==4)&&(i/(a+b)==7))printf("%dt",i);}getch();return 0;}

  
Login to rate this answer.
Suyash Patil

Answered On : Jul 22nd, 2011

Code
  1. #include<stdio.h>
  2. #include<conio.h>
  3.  
  4.  void main()
  5. {clrscr();
  6.  
  7.  int n, x,y,z;
  8.  
  9.  printf("nEnter the number you want to check for");
  10.  
  11.  scanf("%d",&n);
  12.  
  13.  y=n%10;
  14.  x=n/10;
  15.  z=x+y;
  16.  
  17.  if(n==3*z)
  18. {
  19.  printf("nThe number is three times some of its digits....");
  20. }
  21.  else
  22.  
  23.  printf("nnEnter some other number");
  24.  
  25. }

  
Login to rate this answer.
Akul Swamy

Answered On : Jun 29th, 2012

View all answers by Akul Swamy

Code
  1.  
  2. #include<stdio.h>
  3. main()
  4. {
  5.   int g,d;
  6.   for(g=30,d=0;g>0,d<30;g--,d++)
  7.     {
  8.        if((((g+d)*2)==60)&&(((g*4)+(d*2))==86)&&(g+d==30))
  9.        { printf("The number of goats and ducks in the farm are %d and %d",g,d);
  10.          break;
  11.        }
  12.     }                        
  13.   system("pause");
  14. }

  
Login to rate this answer.
anusha

Answered On : Aug 6th, 2012

10th ques answer is 62 73 84

Code
  1. #include<stdio.h>
  2. #include<conio.h>
  3. main()
  4. {
  5. int a,b,i,l;
  6. printf("the numbers are:");
  7. for(i=40;i<100;i++)
  8. {
  9. a=i/10;
  10. b=i%10;
  11. if(a>b)
  12. {
  13. if(a-b==4)
  14. {
  15. l=a+b;
  16. if(i/l==7)
  17. {
  18. %d",i);
  19. }
  20. }
  21. }
  22. }
  23. getch();
  24. }

  
Login to rate this answer.
Ranjini

Answered On : Mar 12th, 2013

Given below the code for question 1

Code
  1. /* C program to find a peculiar two digit number which is three times the sum
  2.  * of its digits.
  3.  * Solution :-
  4.  *  let say number is 10x+y
  5.  *  According to the question 10x+y = 3 ( x + y)
  6.  *  10x + y = 3x + 3y
  7.  *  7x = 2y -------> (1)
  8.  *  If any of the two one digit number satisfies the equation (1) , then
  9.  *  the two digit number is (10x+y)
  10.  *
  11.  */
  12.  
  13. #include<stdio.h>
  14.  
  15. int main(void)
  16. {
  17.     int x = 0;
  18.     int y = 0;
  19.  
  20.     for ( x = 1; x < 10; x++)
  21.     {
  22.         for (y = 1; y < 10; y++)
  23.         {
  24.             /*Check the condition 7x == 2y */
  25.             if( (7 * x ) == (2 * y))
  26.             {
  27.                     printf("The two digit number is %d
  28. ", ((10 * x) + y));
  29.             }
  30.         }
  31.     }
  32.  
  33.     return 0;
  34. }
  35.  

  
Login to rate this answer.
Ranjini

Answered On : Mar 12th, 2013

Answer for Q:2

Code
  1. /* Bacteria are known to multiply very rapidly. If a certain container contains
  2.  * just one bacterium on the first day and there are twice as many on the next
  3.  * day. In this manner the number of bacteria in the container doubles itself
  4.  * everyday. Assuming that the container would be full on the 10th day with
  5.  * 13,312 bacteria, find the number of bacteria that was initially in the
  6.  * container on the first day.
  7.  * Solution :-
  8.  *  It is geometrical progression
  9.  *  eg :- a, a*r, a*r*r, a*r*r*r, ...
  10.  *  The n-th term of a geometric sequence with initial value a and
  11.  *  common ratio r is given by
  12.  *  an = a * (r to the power (n-1))
  13.  *  here r = 2
  14.  *  an = 13312
  15.  *  n = 10
  16.  *  13312 = a * (2 to the power (10 - 1))
  17.  *  13312 = a * (2 to the power 9)
  18.  *  a = 13312 / (2 to the power 9)
  19.  */
  20.  
  21.  
  22. #include<stdio.h>
  23. #include<math.h>
  24.  
  25. int main (void)
  26. {
  27.     int n = 10;
  28.     int an = 13312;     //nth term of gp , here n is 10 .
  29.     int r = 2;          //common ratio
  30.     int power_value;    //this variable is used for storing (r to the power (n-1))
  31.     float a;              //scale factor
  32.  
  33.     power_value = pow(2, 9);
  34.     // a = an/(2 to the power (n - 1))
  35.     a = an / power_value;
  36.     printf(" The number of bacteria initially present in the container on the first day is %f
  37. ", a);
  38.     return 0;
  39. }
  40.  

  
Login to rate this answer.
Ranjini

Answered On : Mar 15th, 2013

Answer to the question 4

Code
  1. /*
  2.  * A number of Cats got together and decided to kill between them 999919 mice.
  3.  * Every cat killed equal number of mice. Write a program to find number of cats
  4.  * soln:-
  5.  *  total number of cats = x
  6.  *  total number of mice = 999919
  7.  *  number of mice killed by cat = y
  8.  *  xy = 999919
  9.  */
  10.  
  11.  
  12. #include<stdio.h>
  13.  
  14. int main(void)
  15. {
  16.     int n_of_cats = 0;
  17.     int total_mice = 999919;
  18.     int n_of_mice_killed_by_each_cat = 0;
  19.     int exit_flag = 0;
  20.  
  21.     for( n_of_mice_killed_by_each_cat = 2; n_of_mice_killed_by_each_cat <= 999919; n_of_mice_killed_by_each_cat++)
  22.     {
  23.         for(n_of_cats = 2; n_of_cats <= 999919; n_of_cats++)
  24.         {
  25.             if((n_of_cats * n_of_mice_killed_by_each_cat) == 999919)
  26.             {
  27.                 printf("Each cat killed %d mice and total number of cats present are %d
  28. ", n_of_mice_killed_by_each_cat, n_of_cats);
  29.                 exit_flag = 1;
  30.             }
  31.         }
  32.         if(exit_flag == 1)
  33.         {
  34.             break;
  35.         }
  36.     }
  37.  
  38.     return 0;
  39. }
  40.  

  
Login to rate this answer.
Ranjini

Answered On : Mar 15th, 2013

Answer to the question - 5

Code
  1. /*
  2.  * Consider the following number 45*45=2025; 20+25=45.Write a program to
  3.  * generate number between 32 and 99 that satisfies the above property.
  4.  * Soln:-
  5.  *  x * x = 100y + z
  6.  *  y + z = x
  7.  *  (y + z) * (y + z) = 100y + z
  8.  *
  9.  */
  10.  
  11. #include<stdio.h>
  12.  
  13. int main(void)
  14. {
  15.     int y = 0;
  16.     int z = 0;
  17.     int x = 0;
  18.     int i = 0;
  19.     for(y = 1; y < 98; y++)
  20.     {
  21.         if( y == 20 )
  22.         {
  23.             continue;
  24.         }
  25.         for( z = 1; (z + y) < 98 ; z++)
  26.         {
  27.             x = y + z;
  28.             if ( x < 33 || x > 99)
  29.             {
  30.                 continue;
  31.             }
  32.             if(x * x == ((100 * y) + z))
  33.             {
  34.                 printf(" The number which follows the propery ( 45 * 45 = 2025 ; 20 + 25 = 45 ) is %d  
  35.  And the property is ( %d * %d = %d ; %d + %d = %d)
  36. ", x, x, x, (x * x), (x *x)/100, (x *x )%100, x);
  37.             }
  38.         }
  39.     }
  40.  
  41.     return 0;
  42. }
  43.  

  
Login to rate this answer.
Ranjini

Answered On : Mar 15th, 2013

Answer to the question 6

Code
  1. /*
  2.  * Rita has a money pouch containing Rs.700. There are equal number of
  3.  * 25 paise coins, 50 paise and one rupee coins. Write a C program to find
  4.  * how many of each are there?
  5.  * Soln:-
  6.  * total amount = 700
  7.  * coins present are 25 paise, 50 paise and 1 rupee
  8.  * Let x be the total count of each coins
  9.  * then
  10.  * x * (25 + 50 + 100) = 700 * 100
  11.  * x * 175 = 700 * 100
  12.  * x = 700 * 100 /175 = 400
  13.  *
  14.  */
  15.  
  16. #include<stdio.h>
  17.  
  18. int main(void)
  19. {
  20.     int total_amt_in_paise = 700 * 100 ;
  21.     int sum_of_three_coins = 25 + 50 + 100 ;
  22.     int count_of_each_coin = 0;
  23.  
  24.     count_of_each_coin = total_amt_in_paise / sum_of_three_coins ;
  25.  
  26.     printf("The total count of each coins(25paise, 50paise, 1rs) is %d
  27. ", count_of_each_coin);
  28.  
  29.     return 0;
  30. }
  31.  

  
Login to rate this answer.
manasa

Answered On : Mar 15th, 2013

Code
  1.  
  2. #include<stdio.h>
  3. main()
  4. { int a=27,b,p,sum;
  5.         b=a;
  6.         while(b>0)
  7.         {
  8.                 p=b%10;
  9.                 sum=sum+p;
  10.                 b=b/10;
  11.                 }
  12.                 if(a==(3*sum))
  13.                
  14.                 printf("
  15. %d is the REQUIRED number:");
  16.                         else
  17.                         printf("
  18. not THE REQUIRED number:");
  19.                        

  
Login to rate this answer.
ranjini

Answered On : Mar 15th, 2013

Answer to the Question 9

Code
  1. /*
  2.  *  Write a C program to find a three digit number which is greater than the
  3.  *  aggregate of its third, tenth and the twelfth parts by 58.
  4.  *  Soln:-
  5.  *  Let x be the 3 digit number .
  6.  *  x = (x / 3) + (x /10 ) + (x /12) + 58
  7.  *  x = ( 120 x + 36 x + 30 x )/ 360 + 58
  8.  *  360 x - 186 x = 58 * 360
  9.  *  174 x = 58 * 360
  10.  *  x = (58 * 360 ) / 174
  11.  */
  12.  
  13.  
  14. #include<stdio.h>
  15.  
  16. int main(void)
  17. {
  18.     float x ;
  19.  
  20.     for(x = 100; x < 1000; x++)
  21.     {
  22.         if(x == ((x / 3) + (x / 10) + (x / 12)) + 58)
  23.         {
  24.             printf("%f
  25. ", x);
  26.         }
  27.     }
  28.  
  29.     return 0;
  30. }
  31.  

  
Login to rate this answer.
ranjini

Answered On : Mar 15th, 2013

Answer to the question 1

Code
  1. /* C program to find a peculiar two digit number which is three times the sum
  2.  * of its digits.
  3.  * Solution :-
  4.  *  let say number is 10x+y
  5.  *  According to the question 10x+y = 3 ( x + y)
  6.  *
  7.  */
  8.  
  9. #include<stdio.h>
  10.  
  11. int main(void)
  12. {
  13.     int x = 0;
  14.     int y = 0;
  15.     int lhs = 0;
  16.     int rhs = 0;
  17.     for ( x = 1; x < 10; x++)
  18.     {
  19.         for (y = 1; y < 10; y++)
  20.         {
  21.             /*Check the condition (10* x )+ y == 3 * ( x + y) */
  22.             lhs = (10 * x) + y;
  23.             rhs = 3 * (x + y);
  24.  
  25.             if( lhs == rhs)
  26.             {
  27.                     printf("The two digit number is %d
  28. ", lhs);
  29.             }
  30.         }
  31.     }
  32.  
  33.     return 0;
  34. }
  35.  

  
Login to rate this answer.
Ranjini

Answered On : Mar 15th, 2013

Answer to the question 10

Code
  1. /*
  2.  * Write a C program to find a two digit number, the second digit of which is
  3.  * smaller than its first digit by 4, and if the number was divided by the
  4.  * digits sum, the quotient would be 7.
  5.  * Soln:-
  6.  * Let the two digits are x and y and two digit number is (10x+y)
  7.  * y = x - 4
  8.  * (10x+y)/x+y = 7
  9.  */
  10.  
  11. #include<stdio.h>
  12.  
  13. int main(void)
  14. {
  15.     float x = 0;
  16.     float y = 0;
  17.  
  18.     for(x = 1; x < 10; x++)
  19.     {
  20.         for(y = 0; y < 10; y++)
  21.         {
  22.             if(((((10 * x) + y ) / (x + y)) == 7) && (y == (x - 4)))
  23.             {
  24.                 printf("The two digit number which satisfy the condition ( (10x+y)/x+y = 7 ) and ( y = x - 4) is %f
  25. ", (10 * x) + y);
  26.             }
  27.         }
  28.     }
  29.    return 0;
  30. }
  31.  

  
Login to rate this answer.
muskan

Answered On : Jul 29th, 2013

Code
  1. #include<stdio.h>
  2. #include<conio.h>
  3.  
  4. int main()
  5. {
  6.     int n;
  7.     printf("enter the number");
  8.     scanf("%d",&n);
  9.     int a = n/10;
  10.     int b= n%10;
  11.     int c = a+b;
  12.     int x= n/c;
  13.     if(x==3)
  14.     printf("the number which is 3 times of sum of its digit is:%d",n);
  15.     getch();
  16.     return 0;
  17. }
  18.  

  
Login to rate this answer.
muskan

Answered On : Jul 29th, 2013

Q:2;

Code
  1. #include<stdio.h>
  2. #include<conio.h>
  3.  
  4. int main()
  5. {
  6.     int n;
  7.     n=13312;
  8.   int i;
  9.     for(i=0;i<10;i++)
  10.     n=n/2;
  11.    
  12.     printf("no. of bacteria in container : %d",n);
  13.  
  14.    
  15.     getch();
  16.     return 0;
  17. }
  18.  

  
Login to rate this answer.
muskan

Answered On : Aug 1st, 2013

Q3:Calculate the factorial of a number recursively. From that calculate the value of COS(X) = 1 - X2/2! + X4 /4! - X6/ 6! +. . .+Xn/n!.

Code
  1. #include<stdio.h>
  2. #include<conio.h>
  3.  
  4. long factorial1(int n);
  5.  
  6. int main()
  7. {
  8.     int n;
  9.   int i;
  10.   long fact=1;
  11.  
  12. printf("enter the number:");
  13. scanf("%d",&n);
  14. int x;    
  15. printf("enter X:");
  16. scanf("%d",&x);
  17.  
  18.  float sum=0;
  19.  
  20. for(i=0;i<=n;i++)
  21. {
  22.  int m= i%2;
  23.  if(m==0)
  24.  {
  25.     m=i/2;
  26.     if(m%2==0)
  27.      {
  28.        sum = sum+(float)(pow(x,i)/factorial1(i));
  29.        }  
  30.        else
  31.        {
  32.        sum = sum - (float)(pow(x,i)/factorial1(i));                
  33.        }
  34.  
  35.  
  36. }
  37.  
  38. }    
  39. printf("cos(x):%f",sum);
  40.     getch();
  41.     return 0;
  42. }
  43.  
  44.  
  45.  
  46. long factorial1(int n)
  47. {
  48.      
  49.      if(n==0)
  50.      return 1;
  51.      else
  52.    return (factorial1(n-1) * n);
  53.          
  54.      
  55.      
  56.  }
  57.  

  
Login to rate this answer.

Code
  1. //answer to 2025 question
  2.  
  3. #include<stdio.h>
  4.  
  5. main()
  6.  
  7. {
  8.  
  9. printf("only for two digit numbers...
  10. ");
  11.  
  12. int x,y,i;
  13.  
  14. int b=0;
  15.  
  16.  
  17. for(i=10;i<100;i++)
  18.  
  19. {
  20.  
  21. b=0;
  22.  
  23. x=i*i;
  24.  
  25.  
  26. while(x)
  27.  
  28. {
  29.  
  30. y=x;
  31.  
  32. b=b+(y%100);
  33.  
  34.  
  35. x=x/100;
  36.  
  37.  
  38. }
  39.  
  40. if(b==i)
  41.  
  42. printf("number=%d, num*num=%d
  43. ",i,i*i);
  44.  
  45. }
  46.  
  47. }
  48.  

  
Login to rate this answer.

Code
  1. //code for goat and duck
  2. #include<stdio.h>
  3.  
  4. //with command line input...
  5.  
  6. main(int argc,char **argv)
  7.  
  8. {
  9.  
  10.  
  11. int eyes,foot,gf,ge,de,df;
  12.  
  13. int r1,r2,cnt1=0,cnt2=0,r3,r4;
  14.  
  15. if(argc!=3)
  16.  
  17. {
  18.  
  19. printf("wrong entry...
  20. ");
  21.  
  22. }
  23.  
  24. else
  25. {
  26.  
  27. eyes=atoi(argv[1]);
  28.  
  29. foot=atoi(argv[2]);
  30.  
  31. ge=eyes/2;
  32.  
  33. printf("two possiblities....
  34. ");
  35.  
  36. printf("**************************************************************
  37. ");
  38.  
  39. printf("first possblity if goats assumed to be more than ducks
  40. ");
  41.  
  42. printf("no of goats: %d
  43. ",(foot/4));
  44.  
  45. printf("foot= %d
  46. ",foot/4);
  47.  
  48. r1=ge-(foot/4);
  49.  
  50. printf("remaing eyes= %d
  51. ",r1);
  52.  
  53. r2=foot-((foot/4)*4);
  54.  
  55. while(r2>=2)
  56.  
  57. {
  58.  
  59. if(cnt1<r1)
  60. cnt1++;
  61.  
  62. r2=r2/2;
  63.  
  64. }
  65.  
  66. printf("remaining foots= %d
  67. ",r2);
  68.  
  69. printf("no of ducks: %d
  70. ",cnt1);
  71.  
  72.  
  73. printf("*****************************************
  74. ");
  75.  
  76. printf("second possblity if ducks assumed to be more than goats
  77. ");
  78.  
  79. r3=foot/2;
  80.  
  81. r4=0;
  82.  
  83. while(r4<r3)
  84.  
  85. {
  86.  
  87. cnt2++;
  88.  
  89.  
  90. r4++;
  91.  
  92. if(cnt2>(eyes/2))
  93.  
  94. break;
  95.  
  96. }
  97.  
  98. printf("no of ducks: %d
  99. ",cnt2);
  100.  
  101. printf("foot= %d
  102. ",foot/2);
  103.  
  104. r1=ge-(foot/2);
  105.  
  106. printf("remaing eyes= %d
  107. ",r1);
  108.  
  109. r2=foot-((foot/2)*2);
  110.  
  111. while(r2>=2)
  112.  
  113. {
  114.  
  115. if(cnt1<r1)
  116.  
  117. cnt1++;
  118.  
  119. r2=r2/2;
  120.  
  121. }
  122.  
  123. printf("remaining foots= %d
  124. ",r2);
  125.  
  126. printf("no of goats: %d
  127. ",cnt1);
  128.  
  129.  
  130.  
  131. }
  132.  
  133.  
  134.  
  135.  
  136. }
  137.  
  138.  

  
Login to rate this answer.
paritosh

Answered On : Aug 24th, 2014

#include
using namespace std;
int main()
{
int end=13312;
for(int i=0;i

  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.