Question discussion

What is the output of the following C program?#include int main() { int x = 10, y = 3; printf("%d %d %.2f %d", x / y, x % y, (float)x / y,…

1145Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following C program?

#include <stdio.h>
int main() {
    int x = 10, y = 3;
    printf("%d %d %.2f %d", x / y, x % y,
           (float)x / y, -x / y);
    return 0;
}
  • A3 1 3.33 -4
  • B3 1 3.33 -3
  • C3 3 3.33 -3
  • D4 1 3.33 -3
Correct answer: B

Explanation

Integer division truncates towards zero: 10/3 = 3, 10%3 = 1, the float division gives 3.33 and −10/3 = −3.

Discussion 0

Nobody has replied yet. Start the discussion!