Question discussion

What is the output of the following C program?#include int main() { int i = 0, s = 0; do { s += i; i += 3; } while (i < 10 && s < 15); prin…

1554Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following C program?

#include <stdio.h>
int main() {
    int i = 0, s = 0;
    do {
        s += i;
        i += 3;
    } while (i < 10 && s < 15);
    printf("%d %d", i, s);
    return 0;
}
  • A12 18
  • B9 9
  • C12 9
  • D9 18
Correct answer: A

Explanation

After the passes (i, s) = (3, 0), (6, 3), (9, 9) and (12, 18), the condition fails because 12 is not less than 10.

Discussion 0

Nobody has replied yet. Start the discussion!