Program even and odd
Program
#include <stdio.h>
int main() {
int num;
// Input from user
printf("Enter a number: ");
scanf("%d", &num);
// Check even or odd
if (num % 2 == 0) {
printf("The number is Even");
} else {
printf("The number is Odd");
}
return 0;
}
Explain
- % is the modulus operator (gives remainder).
- If num % 2 == 0 → number is even
- Otherwise → number is odd
If you want, I can also show:
- Program using loop (multiple numbers)
- Program without using % operator
Comments
Post a Comment