TCS
Company
Programming
Definition
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 ) ;
}
Read Solution (Total 8)
-
- Output : 0, 2, 0.000000, 2.000000
k = i/j => 2/3 = 0
i/j*j = 0*3 = 0
l = j/i => 3/2 = 1
j/i*i = 1*2 = 2
a = i/j => 2/3 = 0.000000 [since a is a float variable, it store the decimal value]
i/j*j = 0.000000*0.000000 = 0.000000 [ Ibn programming, a smaller no. cant divide a larger no.]
b = j/i => 3/2 => 1.000000
j/i*i = 1.000000 * 2 = 2.000000
- 10 years agoHelpfull: Yes(29) No(8)
- As here there is no brackets so first precedence is given to multiplication and then division.
K = 2/3*3 => 2/9 => 0 (because k is int)
l = 3/2*2 => 2/4 => 0 (because l is int)
a = 2/3*3 => 2/9 => 0.222223 (because a is float)
b = 3/2*2 => 3/4 => 0.75 (because b is float) - 9 years agoHelpfull: Yes(8) No(5)
- 0 2 0.000000 2.000000
- 10 years agoHelpfull: Yes(1) No(2)
- 0 2 0.0 2.0
- 9 years agoHelpfull: Yes(1) No(1)
- 0, 2, 0.00000, 2.00000
- 9 years agoHelpfull: Yes(0) No(0)
- k=0,l=0,a=0.6,b=0.7
- 9 years agoHelpfull: Yes(0) No(2)
- 2 3 2.0 3.0
- 6 years agoHelpfull: Yes(0) No(0)
- k=0
l=2
a=0.0
b=2.0 - 3 years agoHelpfull: Yes(0) No(1)
TCS Other Question