(b) What will be the output for the following program C code?
#include<stdio.h>
int main()
{
int x=15, b;
float c;
b=x/2;
c=x/4;
x=x%2;
printf(“ %d %d %f ”, x, b, c);
return 0;
}
Output
1 7 3.000000
Explanation
x=x%2;
The value of x is 15. The modulus of 15 and 2 is 1. Therefore the final value of x will be 1.
b=x/2;
Since b and 2 are integers, 15 divided by 2 results to 7.
c=x/4;
Since c is a float and 4 is an integer, 15 divided by 4 result to 3.000000
Comments
Leave a comment