Question 10
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
int years[] = {1900, 2000, 2023, 2024};
for (int i = 0; i < 4; i++) {
int y = years[i];
putchar(y % 400 == 0 ? 'L' : y % 100 == 0 ? 'N' : y % 4 == 0 ? 'L' : 'N');
}
putchar('\n');
return 0;
}
- A NLNL Correct
- B LLNL
- C NLLL
- D LNNL
Correct Answer: Option A
The tests run from the most specific rule to the most general: divisible by 400 → leap; else by 100 → not leap; else by 4 → leap. 1900 is divisible by 100 but not 400, so it is not a leap year.
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!