ProgrammingHardWipro · Cognizant pattern

What is printed?

What is printed?
int main(void) {
    int a = 10, b = 3;
    printf("%d %d %f", a / b, a % b, (float)a / b);
}
  1. A. 3 0 3.333333
  2. B. 3 1 3.333333
  3. C. 3.33 1 3.33
  4. D. 3 1 3.000000

Correct answer: B. 3 1 3.333333

Integer division a/b truncates toward zero: 10/3=3. a%b = 10 - 3*3 = 1. Casting a to float before dividing gives true floating-point division: 10.0/3 ≈ 3.333333.

More C Programming questions

Exams that ask this topic