LearnFrenzy
Sign in Take a free test

C Loops · Predict the Output · Question 5

Summing with continue to skip odd numbers Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 5 Back to Exercise

What is the output of the following C program?

main.c
#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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links