Tuesday, July 04, 2006

Predict the Output (If else problems)

The following are various Predict the output problems..basically on if-else cuz thats what I am learning right now..:)

The file that you can find at the bottom of this post has all the snippets commented out.
Just remove the /* and */ and compile the program so you get the output.

The answers are provided at the bottom of the page.



1)

int a=300,b,c;

if (a>=400)
b=300;
c=200;

printf ("\n%d %d",b, c);





2)

int a=500,b,c;

if (a>=400)
b=300;
c=200;

printf ("\n%d %d",b,c);




3)

int x=10,y=20;

if (x==y);
printf ("\n %d %d",x,y);





4)

int x=3,y=5;
if (x==3)

printf ("\n%d",x);
else;
printf ("\n%d",y);






5)

int x=3;
float y=3.0;

if (x==y)
printf ("\nx and y are equal");

else
printf ("\nx and y are not equal");





6)

int x=3,y,z;

y=x=10;
z=x<10;
printf ("\nx=%d y=%d z=%d",x,y,z);

*/






7)

int k=35;
printf ("\n%d %d %d ",k==35, k=50, k>40);






ANSWERS:
1) #random no. 200

2)300 200

3)10 20

4) 3
5

5) x and y are equal

6) x=10 y=10 z=0

7) 0 50 0











The File can be found at:
Download File

No comments: