Let us learn how to check if a number is positive, negative or zero and implement a C program to check if a number is positive or negative using Arrays, For and If Else Loop.
Positive and Negative Numbers
To check whether an integer is negative or positive, we need to compare it with zero essentially.
Here’s the number line that will help you do the comparison and find whether the number is less or greater than zero.

Algorithm To Find Whether A Number Is Positive Or Negative
- Input a number from the user
- If number is less than zero, then it is a negative integer
- Else If number is greater than zero, then it is a positive integer
- Else, the number is equal to zero
- End
Note: This code to find whether an integer is positive or negative in C programming is compiled with GNU GCC compiler on CodeLite IDE. However, these codes are compatible with all other operating systems.
Must Read: C Program To Find Quotient of a Number
C Program To Check If A Number Is Positive Or Negative
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include<stdio.h> int main() { int number; printf("Enter a Number:\t"); scanf("%d", &number); if(number > 0) { printf("\n%d is a Positive Number\n", number); } else if(number < 0) { printf("\n%d is a Negative Number\n", number); } else if(number == 0) { printf("\n%d is equal to zero\n", number); } return 0; } |
Must Read: C Program For Age Calculator
Output

Must Read: C Program To Print Pascal Triangle
Method 2: C Program To Find Positive Or Negative Number In Array
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #include<stdio.h> int main() { int array[30], count, limit; printf("\nEnter the limit of the array:\t"); scanf("%d", &limit); for(count = 0; count < limit; count++) { printf("Enter the element:\t"); scanf("%d", &array[count]); } printf("\n\nThe array elements are as follows:\n\n"); for(count = 0; count < limit; count++) { printf("%d\t", array[count]); } for(count = 0; count < limit; count++) { if(array[count] < 0) { printf("\n%d is a Negative Integer\n", array[count]); } else if(array[count] > 0) { printf("\n%d is a Positive Integer\n", array[count]); } else { printf("\n%d is equal to Zero\n", array[count]); } } return 0; } |
Must Read: C Program To Display Digital Clock
Output

Let’s discuss more on this C program to check if a number is positive or negative or zero in the comment section below. Also, let us know if you have any compilation errors and any doubts about the same.