Search Placementyogi.com
 
2

What is the output of the following program:

void main( )
{
int i = 2, j = 3, k, l ;
float a, b ;
k = i / j * j ;
l = j / i * i ;
a = i / j * j ;
b = j / i * i ;
printf( "%d %d %f %f", k, l, a, b ) ;
}
A.

3 3 2 2

B.

3 3 0 2.000000

C.

3 2 0.000000 3.000000

D.

0 2 0.000000 2.000000

See Answer & Explanation Lets Discuss
Correct answer is : D
Explanation

RHS is evaluated first and then the value is promoted to float, float arithmetic is not used here as there is no variable on the RHS that is float.
The Float is printed with decimal followed by 6 zeros.

 

vivek 8/3/2013 11:21:09 AM
there is two case in operation 1 is k=2/3*3=2/9=0.something=0 butl=3/2*2=3/4=also 0.somthing=0 2. is k=(2/3)*3=2 if we see both case also ans is not there in choces plz clarify my confusion
Admin 8/3/2013 9:20:03 PM
k= i/j*j=2/3*3=0*3=0; l=j/i*i=3/2*2=1*2=2; a=i/j*j=2/3*3=0*3=0 but a is float so it will be printed as 0.000000; b=j/i*i=3/2*2=1*2=2 again b is float so it will be printed as 2.000000; I hope this answers your question. Please read more : http://placementyogi.com/tutorials/c/operators-in-c/arithmetic-operators-in-c
aaa 8/23/2013 7:21:25 PM
thats very good
alex 9/16/2013 2:03:41 AM
great explanation :)
suchandra 11/26/2013 3:48:20 PM

why there is 6 zeroes?

Athiban 3/21/2014 7:57:57 AM

smart explanation

anshu 9/19/2014 5:35:41 PM

I couldnt get you expain me breifly i am new to the programs

anshu 9/19/2014 5:38:28 PM

I count understand logic i m new to the code . pls any one explain me the logic

Preview

Thanks for posting your comment! It will be visible soon!
Post Another Comment

6
+
5
=

Name:
Email :
Banner to LogicGuns.com

Hide Page Information