LearnFrenzy
Sign in Take a free test

C Loops · Exercise 2 of 4

C Loops Predict the Output

  • 12 questions
  • Page 2 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Read each program and choose what it prints. Every program was compiled and run, so the answers are the real output.

Question 11 Hard

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    for (int i = 0; i < 4; i++) {
        switch (i) {
        case 1:
            printf("one ");
            break;
        case 2:
            printf("two ");
            continue;
        default:
            printf("%d ", i);
        }
        printf("| ");
    }
    printf("\n");
    return 0;
}
A 0 | one | two 3 |
B 0 | one | two | 3 |
C 0 | one
D 0 one two 3
Question page & discussion
Question 12 Easy

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    for (int r = 1; r <= 4; r++) {
        for (int c = 1; c <= r; c++)
            printf("%d", c % 2);
        printf("\n");
    }
    return 0;
}
A 1 10 101 1010
B 1 01 101 0101
C 1 11 111 1111
D 0 01 010 0101
Question page & discussion
Up next · Exercise 3Find the Error8 questions

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links