# 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.

#### BECKONLAND2004 Profile Answers by BECKONLAND2004

• May 27th, 2008

Write a C-COde to blink the character

#### ravikth Profile Answers by 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

#### shreekanthss Profile Answers by shreekanthss

• Feb 2nd, 2009

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 Profile Answers by RamLaw

• Jun 16th, 2009

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

#### milan.kadivar Profile Answers by milan.kadivar

• Jun 16th, 2009

#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 Profile Answers by 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 Profile Answers by 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))
{
return 0;
}

}
return 0;
}

#### npoojasjce Profile Answers by 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);
}
}

#### meenu1992 Profile Answers by 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();
}

#### abhishek tripathi Profile Answers by abhishek tripathi

• Dec 15th, 2009

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

#### Ankur1989 Profile Answers by 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");

}

#### Ankur1989 Profile Answers by 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");

}

#### Ankur1989 Profile Answers by 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);

}

#### Ankur1989 Profile Answers by 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);
}

#### dn007 Profile Answers by dn007

• Jan 27th, 2010

If (3(x+y)=10x+y

= no. is 27

#### vkscool Profile Answers by 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;
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();

}

#### Rohini Dasgupta Profile Answers by Rohini Dasgupta

• Jun 10th, 2011

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

#### Rohini Dasgupta Profile Answers by Rohini Dasgupta

• Jun 10th, 2011

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

#### Rohini Dasgupta Profile Answers by Rohini Dasgupta

• Jun 10th, 2011

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

#### Rohini Dasgupta Profile Answers by Rohini Dasgupta

• Jun 10th, 2011

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

#### Rohini Dasgupta Profile Answers by Rohini Dasgupta

• Jun 13th, 2011

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;

#### Rohini Dasgupta Profile Answers by Rohini Dasgupta

• Jun 13th, 2011

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

#### Suyash Patil

• Jul 22nd, 2011

```Code#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");

}```

#### Akul Swamy Profile Answers by Akul Swamy

• Jun 29th, 2012

```Code
#include<stdio.h>
main()
{
int g,d;
for(g=30,d=0;g>0,d<30;g--,d++)
{
if((((g+d)*2)==60)&&(((g*4)+(d*2))==86)&&(g+d==30))
{ printf("The number of goats and ducks in the farm are %d and %d",g,d);
break;
}
}
system("pause");
}```

#### anusha

• Aug 6th, 2012

62
73

84

```Code#include<stdio.h>
#include<conio.h>
main()
{
int a,b,i,l;
printf("the numbers are:");
for(i=40;i<100;i++)
{
a=i/10;
b=i%10;
if(a>b)
{
if(a-b==4)
{
l=a+b;
if(i/l==7)
{
printf("
%d",i);
}
}
}
}
getch();
}```

#### Ranjini

• Mar 12th, 2013

Given below the code for question 1

```Code/* C program to find a peculiar two digit number which is three times the sum
* of its digits.
* Solution :-
*  let say number is 10x+y
*  According to the question 10x+y = 3 ( x + y)
*  10x + y = 3x + 3y
*  7x = 2y -------> (1)
*  If any of the two one digit number satisfies the equation (1) , then
*  the two digit number is (10x+y)
*
*/

#include<stdio.h>

int main(void)
{
int x = 0;
int y = 0;

for ( x = 1; x < 10; x++)
{
for (y = 1; y < 10; y++)
{
/*Check the condition 7x == 2y */
if( (7 * x ) == (2 * y))
{
printf("The two digit number is %d
", ((10 * x) + y));
}
}
}

return 0;
}
```

#### Ranjini

• Mar 12th, 2013

```Code/* 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.
* Solution :-
*  It is geometrical progression
*  eg :- a, a*r, a*r*r, a*r*r*r, ...
*  The n-th term of a geometric sequence with initial value a and
*  common ratio r is given by
*  an = a * (r to the power (n-1))
*  here r = 2
*  an = 13312
*  n = 10
*  13312 = a * (2 to the power (10 - 1))
*  13312 = a * (2 to the power 9)
*  a = 13312 / (2 to the power 9)
*/

#include<stdio.h>
#include<math.h>

int main (void)
{
int n = 10;
int an = 13312;     //nth term of gp , here n is 10 .
int r = 2;          //common ratio
int power_value;    //this variable is used for storing (r to the power (n-1))
float a;              //scale factor

power_value = pow(2, 9);
// a = an/(2 to the power (n - 1))
a = an / power_value;
printf(" The number of bacteria initially present in the container on the first day is %f
", a);
return 0;
}
```

#### Ranjini

• Mar 15th, 2013

```Code/*
* 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
* soln:-
*  total number of cats = x
*  total number of mice = 999919
*  number of mice killed by cat = y
*  xy = 999919
*/

#include<stdio.h>

int main(void)
{
int n_of_cats = 0;
int total_mice = 999919;
int n_of_mice_killed_by_each_cat = 0;
int exit_flag = 0;

for( n_of_mice_killed_by_each_cat = 2; n_of_mice_killed_by_each_cat <= 999919; n_of_mice_killed_by_each_cat++)
{
for(n_of_cats = 2; n_of_cats <= 999919; n_of_cats++)
{
if((n_of_cats * n_of_mice_killed_by_each_cat) == 999919)
{
printf("Each cat killed %d mice and total number of cats present are %d
", n_of_mice_killed_by_each_cat, n_of_cats);
exit_flag = 1;
}
}
if(exit_flag == 1)
{
break;
}
}

return 0;
}
```

#### Ranjini

• Mar 15th, 2013

Answer to the question - 5

```Code/*
* 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.
* Soln:-
*  x * x = 100y + z
*  y + z = x
*  (y + z) * (y + z) = 100y + z
*
*/

#include<stdio.h>

int main(void)
{
int y = 0;
int z = 0;
int x = 0;
int i = 0;
for(y = 1; y < 98; y++)
{
if( y == 20 )
{
continue;
}
for( z = 1; (z + y) < 98 ; z++)
{
x = y + z;
if ( x < 33 || x > 99)
{
continue;
}
if(x * x == ((100 * y) + z))
{
printf(" The number which follows the propery ( 45 * 45 = 2025 ; 20 + 25 = 45 ) is %d
And the property is ( %d * %d = %d ; %d + %d = %d)
", x, x, x, (x * x), (x *x)/100, (x *x )%100, x);
}
}
}

return 0;
}
```

#### Ranjini

• Mar 15th, 2013

```Code/*
* 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?
* Soln:-
* total amount = 700
* coins present are 25 paise, 50 paise and 1 rupee
* Let x be the total count of each coins
* then
* x * (25 + 50 + 100) = 700 * 100
* x * 175 = 700 * 100
* x = 700 * 100 /175 = 400
*
*/

#include<stdio.h>

int main(void)
{
int total_amt_in_paise = 700 * 100 ;
int sum_of_three_coins = 25 + 50 + 100 ;
int count_of_each_coin = 0;

count_of_each_coin = total_amt_in_paise / sum_of_three_coins ;

printf("The total count of each coins(25paise, 50paise, 1rs) is %d
", count_of_each_coin);

return 0;
}
```

#### manasa

• Mar 15th, 2013

```Code
#include<stdio.h>
main()
{ int a=27,b,p,sum;
b=a;
while(b>0)
{
p=b%10;
sum=sum+p;
b=b/10;
}
if(a==(3*sum))

printf("
%d is the REQUIRED number:");
else
printf("
not THE REQUIRED number:");
```

#### ranjini

• Mar 15th, 2013

```Code/*
*  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.
*  Soln:-
*  Let x be the 3 digit number .
*  x = (x / 3) + (x /10 ) + (x /12) + 58
*  x = ( 120 x + 36 x + 30 x )/ 360 + 58
*  360 x - 186 x = 58 * 360
*  174 x = 58 * 360
*  x = (58 * 360 ) / 174
*/

#include<stdio.h>

int main(void)
{
float x ;

for(x = 100; x < 1000; x++)
{
if(x == ((x / 3) + (x / 10) + (x / 12)) + 58)
{
printf("%f
", x);
}
}

return 0;
}
```

#### ranjini

• Mar 15th, 2013

```Code/* C program to find a peculiar two digit number which is three times the sum
* of its digits.
* Solution :-
*  let say number is 10x+y
*  According to the question 10x+y = 3 ( x + y)
*
*/

#include<stdio.h>

int main(void)
{
int x = 0;
int y = 0;
int lhs = 0;
int rhs = 0;
for ( x = 1; x < 10; x++)
{
for (y = 1; y < 10; y++)
{
/*Check the condition (10* x )+ y == 3 * ( x + y) */
lhs = (10 * x) + y;
rhs = 3 * (x + y);

if( lhs == rhs)
{
printf("The two digit number is %d
", lhs);
}
}
}

return 0;
}
```

#### Ranjini

• Mar 15th, 2013

```Code/*
* 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
* digits sum, the quotient would be 7.
* Soln:-
* Let the two digits are x and y and two digit number is (10x+y)
* y = x - 4
* (10x+y)/x+y = 7
*/

#include<stdio.h>

int main(void)
{
float x = 0;
float y = 0;

for(x = 1; x < 10; x++)
{
for(y = 0; y < 10; y++)
{
if(((((10 * x) + y ) / (x + y)) == 7) && (y == (x - 4)))
{
printf("The two digit number which satisfy the condition ( (10x+y)/x+y = 7 ) and ( y = x - 4) is %f
", (10 * x) + y);
}
}
}
return 0;
}
```

#### muskan

• Jul 29th, 2013

```Code#include<stdio.h>
#include<conio.h>

int main()
{
int n;
printf("enter the number");
scanf("%d",&n);
int a = n/10;
int b= n%10;
int c = a+b;
int x= n/c;
if(x==3)
printf("the number which is 3 times of sum of its digit is:%d",n);
getch();
return 0;
}
```

#### muskan

• Jul 29th, 2013

Q:2;

```Code#include<stdio.h>
#include<conio.h>

int main()
{
int n;
n=13312;
int i;
for(i=0;i<10;i++)
n=n/2;

printf("no. of bacteria in container : %d",n);

getch();
return 0;
}
```

#### 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#include<stdio.h>
#include<conio.h>

long factorial1(int n);

int main()
{
int n;
int i;
long fact=1;

printf("enter the number:");
scanf("%d",&n);
int x;
printf("enter X:");
scanf("%d",&x);

float sum=0;

for(i=0;i<=n;i++)
{
int m= i%2;
if(m==0)
{
m=i/2;
if(m%2==0)
{
sum = sum+(float)(pow(x,i)/factorial1(i));
}
else
{
sum = sum - (float)(pow(x,i)/factorial1(i));
}

}

}
printf("cos(x):%f",sum);
getch();
return 0;
}

long factorial1(int n)
{

if(n==0)
return 1;
else
return (factorial1(n-1) * n);

}
```

#### sourav punoriyar Profile Answers by sourav punoriyar

• Sep 5th, 2013

```Code//answer to 2025 question

#include<stdio.h>

main()

{

printf("only for two digit numbers...
");

int x,y,i;

int b=0;

for(i=10;i<100;i++)

{

b=0;

x=i*i;

while(x)

{

y=x;

b=b+(y%100);

x=x/100;

}

if(b==i)

printf("number=%d, num*num=%d
",i,i*i);

}

}
```

#### sourav punoriyar Profile Answers by sourav punoriyar

• Sep 5th, 2013

```Code//code for goat and duck
#include<stdio.h>

//with command line input...

main(int argc,char **argv)

{

int eyes,foot,gf,ge,de,df;

int r1,r2,cnt1=0,cnt2=0,r3,r4;

if(argc!=3)

{

printf("wrong entry...
");

}

else
{

eyes=atoi(argv);

foot=atoi(argv);

ge=eyes/2;

printf("two possiblities....
");

printf("**************************************************************
");

printf("first possblity if goats assumed to be more than ducks
");

printf("no of goats: %d
",(foot/4));

printf("foot= %d
",foot/4);

r1=ge-(foot/4);

printf("remaing eyes= %d
",r1);

r2=foot-((foot/4)*4);

while(r2>=2)

{

if(cnt1<r1)
cnt1++;

r2=r2/2;

}

printf("remaining foots= %d
",r2);

printf("no of ducks: %d
",cnt1);

printf("*****************************************
");

printf("second possblity if ducks assumed to be more than goats
");

r3=foot/2;

r4=0;

while(r4<r3)

{

cnt2++;

r4++;

if(cnt2>(eyes/2))

break;

}

printf("no of ducks: %d
",cnt2);

printf("foot= %d
",foot/2);

r1=ge-(foot/2);

printf("remaing eyes= %d
",r1);

r2=foot-((foot/2)*2);

while(r2>=2)

{

if(cnt1<r1)

cnt1++;

r2=r2/2;

}

printf("remaining foots= %d
",r2);

printf("no of goats: %d
",cnt1);

}

}

```

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

~
~

#### 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    #define MAX_POSSIBLE_NUM 3*(9+9)
int num_to_check;
float a=0,b=0;

for(a=0;a<=(MAX_POSSIBLE_NUM/10);a++){
for(b=0;b<=9;b++){
num_to_check = (int)((a/10 + b/100)*100);
if(num_to_check == 3*(a+b))
printf("Number to check = %d
", num_to_check);
}
}
```

#### Rohan

• Jun 18th, 2015

I dont know if its optimized but works

```Code{/*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 */

int num_goats=0, num_ducks=0, animals=0;
int eyes = 60, feet = 86;

animals = eyes/2;

for(num_goats=0;num_goats<animals;num_goats++){
for(num_ducks=0;num_ducks<animals;num_ducks++){
if((num_goats*4 + num_ducks*2 == feet ) && (num_goats*2 + num_ducks*2 == eyes) && (num_goats + num_ducks == animals))
printf("Goats :: %d & Ducks :: %d
", num_goats,num_ducks);

}
}
}
```

#### Aneesh

• Jul 29th, 2016

27

```Code#include<stdio.h>
#include<conio.h>
void main()
{
int i,k,a,sum=0;
clrscr();
for(i=10;i<=99;i++)
{
k=i;
a=k%10;
k=k/10;
sum=(a+k)*3;
if(sum==i)
printf("%d",i);
}
getch();
}```  