LearnFrenzy
Sign in Take a free test

Decision Making · Predict the Output · Question 2

De Morgan in practice: two forms of "outside 10–20" Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 2 Back to Exercise

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    int tests[] = {5, 15, 25};
    for (int i = 0; i < 3; i++) {
        int x = tests[i];
        printf("%d%d ", !(x >= 10 && x <= 20), x < 10 || x > 20);
    }
    printf("\n");
    return 0;
}
  • A 11 00 11 Correct
  • B 10 01 10
  • C 11 11 11
  • D 00 11 00
Correct Answer: Option A

By De Morgan, "not (≥ 10 and ≤ 20)" equals "< 10 or > 20", so both columns always agree: true for 5 and 25, false for 15.

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