Question discussion

What is the output of the following C program?#include int main() { int i, s = 0; for (i = 1; i 8) break; s += i; } printf("%d %d", s, i);…

1180Medium 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, s = 0;
    for (i = 1; i <= 10; i++) {
        if (i % 3 == 0) continue;
        if (i > 8) break;
        s += i;
    }
    printf("%d %d", s, i);
    return 0;
}
  • A27 9
  • B27 10
  • C36 10
  • D30 10
Correct answer: B

Explanation

The sum of 1, 2, 4, 5, 7, 8 is 27; i = 9 is skipped by continue and i = 10 triggers break, so i is 10.

Discussion 0

Nobody has replied yet. Start the discussion!