- The program first declares a variable
num to store the user input. - It then prompts the user to enter a number using the
printf() and scanf() functions. - An
if-else statement is used to check whether num is even or odd using the modulo operator %. If the remainder of num divided by 2 is equal to 0, the program prints that num is even. Otherwise, the program prints that num is odd. - Finally, the program returns 0 to indicate successful execution.
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num % 2 == 0) {
printf("%d is even.", num);
} else {
printf("%d is odd.", num);
}
return 0;
}
OUTPUT
Enter a number: 7
7 is odd.