C Program to Check Whether a Number is Positive, Negative, or Zero
This program takes a number as input from the user and checks whether it is positive, negative, or zero using if-else statements.
Concept Overview
A number is positive if it is greater than 0, negative if it is less than 0, and zero if it equals 0. We use conditional statements to determine the result.
Program
C
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num > 0)
printf("%d is a positive number.\n", num);
else if (num < 0)
printf("%d is a negative number.\n", num);
else
printf("%d is zero.\n", num);
return 0;
}
Sample Output
Enter a number: -7 -7 is a negative number.
Explanation
- `if (num > 0)` – Checks if the number is positive.
- `else if (num < 0)` – Checks if the number is negative.
- `else` – If neither, the number is zero.
- `printf()` – Displays the result on the screen.
Note: Note: This program uses simple if-else statements, which is suitable for beginners.
Codecrown