Search⌘ K
AI Features

Eenie, Meenie, Miney, Mod

Explore the modulus operation in this C programming puzzle. Understand how to analyze code snippets, predict outputs, and deepen your grasp of arithmetic operations within C programs. This lesson helps strengthen your problem-solving skills with practical C code challenges.

We'll cover the following...

Puzzle code

Read carefully the code given below:

C
#include <stdio.h>
int main()
{
int m = 1;
while( m<10 ) {
if( 2%m )
printf("%d - Odd\n", m);
else
printf("%d - Even\n", m);
m++;
}
return(0);
}

Your task: Guess the output

Attempt the following test to assess your understanding.

What is the expected output of the above code?

1.
A.
1 - Odd
2 - Odd
3 - Odd
4 - Odd
5 - Odd
6 - Odd
7 - Odd
8 - Odd
9 - Odd
B.
1 - Even
2 - Odd
3 - Even
4 - Odd
5 - Even
6 - Odd
7 - Even
8 - Odd
9 - Even
C.
1 - Even
2 - Even
3 - Odd
4 - Odd
5 - Odd
6 - Odd
7 - Odd
8 - Odd
9 - Odd
D.
1 - Odd
2 - Odd
3 - Odd
4 - Odd
5 - Odd
6 - Odd
7 - Odd
8 - Even
9 - Even

1 / 1

Let's discuss the code and output together in the next lesson.