C Program to check even or odd.
#include <stdio.h>
int main() {
int n;
printf("Enter an integer: ");
scanf("%d", &n);
if(n%2==0) {
printf("%d is even number.",n);
}
else {
printf("%d is odd number.",n);
}
return 0;
}
Output
Enter an integer: 23
23 is a odd number.
Explanation
- If test expression becomes true : statement inside if get executed and else statement get skipped from execution.
- If test expression becomes false : statement inside if get skipped from execution and else statement get executed.
- Here when user enters 23, test expression n%2==0 becomes false.Hence else statement get executed.
Comments
Post a Comment