ProgrammingHardGATE CS · Infosys

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    int s = 0;
    for (int i = 0; i < 10; i++) {
        if (i % 3 == 0) continue;
        if (i > 7) break;
        s += i;
    }
    printf("%d", s);
}
  1. A. 27
  2. B. 19
  3. C. 21
  4. D. 12

Correct answer: B. 19

The multiples of 3 are skipped, and the loop stops at i = 8. The values added are 1, 2, 4, 5 and 7, which total 19.

More C Programming questions

Exams that ask this topic