Question 5
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
int sum = 0;
for (int i = 1; i <= 10; i++) {
if (i % 2)
continue;
sum += i;
}
printf("%d\n", sum);
return 0;
}
- A 30 Correct
- B 25
- C 55
- D 20
Correct Answer: Option A
i % 2 is non-zero (true) for odd numbers, so they are skipped. The even numbers 2 + 4 + 6 + 8 + 10 = 30 are added.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!