Question
Check if a number is positive, negative, or zero, and even/odd if positive.
Solution
β Verified
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num > 0) {
printf("The number is positive.\n");
if (num % 2 == 0) {
printf("It is even.\n");
} else {
printf("It is odd.\n");
}
} else if (num < 0) {
printf("The number is negative.\n");
} else {
printf("The number is zero.\n");
}
return 0;
}
Click here to download practice questions on
If Else StatementMore Questions on If Else Statement
Question 2
Check if a person can vote and also check if they are a senior citizen using nested if.
View solution
Question 7
Write a program in C to Check whether a character is uppercase or lowercase.
View solution
Question 12
Write a program in C to Check if a person is eligible to vote by checking his or her age.
View solution