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.

Questions by ganesan81

Showing Answers 1 - 43 of 43 Answers

ravikth

  • Oct 31st, 2008
 

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

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();
}

RamLaw

  • Jun 16th, 2009
 

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;
}

#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();
}

jothejo2

  • Jun 26th, 2009
 

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;
          }
}

ranjini.np

  • Aug 6th, 2009
 

/* 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;
}

  Was this answer useful?  Yes

npoojasjce

  • Oct 13th, 2009
 

#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);
     }
}

  Was this answer useful?  Yes

meenu1992

  • Oct 23rd, 2009
 

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();
}

Ankur1989

  • Jan 22nd, 2010
 

#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 ....");
 }
   else
printf(""nnEnter Some other number");

}

  Was this answer useful?  Yes

Ankur1989

  • Jan 22nd, 2010
 


//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");
 
}

  Was this answer useful?  Yes

Ankur1989

  • Jan 22nd, 2010
 

//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);

 }

 

  Was this answer useful?  Yes

Ankur1989

  • Jan 22nd, 2010
 

#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);
 }

  Was this answer useful?  Yes

vkscool

  • Sep 19th, 2010
 

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();

 }

  Was this answer useful?  Yes

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;
}

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;
}

  Was this answer useful?  Yes

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;

  Was this answer useful?  Yes

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;
}

  Was this answer useful?  Yes

Suyash Patil

  • Jul 22nd, 2011
 

Code
  1. #include<stdio.h>

  2. #include<conio.h>

  3. "nEnter the number you want to check for");

  4.  

  5.  scanf("%d""nThe number is three times some of its digits....""nnEnter some other number");

  6.  

  7. }

  Was this answer useful?  Yes

anusha

  • Aug 6th, 2012
 

10th ques answer is
62
73

84

Code
  1. #include<stdio.h>

  2. #include<conio.h>

  3. "the numbers are:""

  4. %d",i);

  5. }

  6. }

  7. }

  8. }

  9. getch();

  10. }

  Was this answer useful?  Yes

Ranjini

  • 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. /*Check the condition 7x == 2y */"The two digit number is %d

  15. "

  Was this answer useful?  Yes

Ranjini

  • 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. //nth term of gp , here n is 10 .//common ratio//this variable is used for storing (r to the power (n-1))//scale factor

  25.  

  26.     power_value = pow(2, 9);

  27.     // a = an/(2 to the power (n - 1))" The number of bacteria initially present in the container on the first day is %f

  28. "

  Was this answer useful?  Yes

Ranjini

  • 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. "Each cat killed %d mice and total number of cats present are %d

  14. "

  Was this answer useful?  Yes

Ranjini

  • 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. " The number which follows the propery ( 45 * 45 = 2025 ; 20 + 25 = 45 ) is %d  

  13.  And the property is ( %d * %d = %d ; %d + %d = %d)

  14. "

  Was this answer useful?  Yes

Ranjini

  • 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. "The total count of each coins(25paise, 50paise, 1rs) is %d

  18. "

  Was this answer useful?  Yes

manasa

  • Mar 15th, 2013
 

Code
  1.  

  2. #include<stdio.h>

  3. "

  4. %d is the REQUIRED number:""

  5. not THE REQUIRED number:");

  6.                        

  Was this answer useful?  Yes

ranjini

  • 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. "%f

  16. "

  Was this answer useful?  Yes

ranjini

  • 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. /*Check the condition (10* x )+ y == 3 * ( x + y) */"The two digit number is %d

  11. "

  Was this answer useful?  Yes

Ranjini

  • 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. "The two digit number which satisfy the condition ( (10x+y)/x+y = 7 ) and ( y = x - 4) is %f

  13. "

  Was this answer useful?  Yes

muskan

  • Jul 29th, 2013
 

Code
  1. #include<stdio.h>

  2. #include<conio.h>

  3. "enter the number");

  4.     scanf("%d""the number which is 3 times of sum of its digit is:%d"

  Was this answer useful?  Yes

muskan

  • Jul 29th, 2013
 

Q:2;

Code
  1. #include<stdio.h>

  2. #include<conio.h>

  3. "no. of bacteria in container : %d"




  Was this answer useful?  Yes

muskan

  • 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. "enter the number:");

  4. scanf("%d""enter X:");

  5. scanf("%d""cos(x):%f"


  Was this answer useful?  Yes

Code
  1. //code for goat and duck

  2. #include<stdio.h>

  3.  

  4. //with command line input..."wrong entry...

  5. ""two possiblities....

  6. ""**************************************************************

  7. ""first possblity if goats assumed to be more than ducks

  8. ""no of goats: %d

  9. ""foot= %d

  10. ""remaing eyes= %d

  11. ""remaining foots= %d

  12. ""no of ducks: %d

  13. ""*****************************************

  14. ""second possblity if ducks assumed to be more than goats

  15. ""no of ducks: %d

  16. ""foot= %d

  17. ""remaing eyes= %d

  18. ""remaining foots= %d

  19. ""no of goats: %d

  20. ",cnt1);

  21.  

  22.  

  23.  

  24. }

  25.  

  26.  

  27.  

  28.  

  29. }

  30.  

  31.  

  Was this answer useful?  Yes

paritosh

  • Aug 24th, 2014
 

#include
using namespace std;
int main()
{
int end=13312;
for(int i=0;i<10;i++)
{
end=end/2;
}
cout<<"The number is :"< return 0;
}

~
~

  Was this answer useful?  Yes

Rohan

  • Jun 18th, 2015
 

It says find the magic number, so we need to check all possible combinations.
Maximum number is 3*(9+9) = 54. So we can check for all numbers from 0 to 54.

Code
  1.     #define MAX_POSSIBLE_NUM 3*(9+9)

  2. "Number to check = %d

  3. ", num_to_check);

  4.         }

  5.     }

  6.  

  Was this answer useful?  Yes

Rohan

  • Jun 18th, 2015
 

I dont know if its optimized but works

Code
  1. {/*There are some goats and ducks in a farm. There are 60 eyes and 86 foot in total.

  2.    Write a program to find number of goats and ducks in the farm */"Goats :: %d & Ducks :: %d

  3. ", num_goats,num_ducks);

  4.  

  5.        }

  6.    }

  7. }  

  8.  

  Was this answer useful?  Yes

Aneesh

  • Jul 29th, 2016
 

27

Code
  1. #include<stdio.h>

  2. #include<conio.h>

  3. "%d",i);

  4.        }

  5.      getch();

  6.   }

  Was this answer useful?  Yes

Give your answer:

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

 

Related Answered Questions

 

Related Open Questions