Google News
logo
C Program to check whether the given integer is positive or negative
In the following program we are checking whether the input integer number is positive or negative. If the input number is greater than zero then its positive else it is a negative number. If the number is zero then it is neither positive nor negative.

Same logic we have followed in the below C program.
Program :
#include
 
void main()
{
    int num;
 
    printf("Enter a number: \n");
    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("0 is neither positive nor negative");
}
Output :
Output 1 :
Enter a number:
0
0 is neither positive nor negative​

 

Output 2 :
Enter a number:
-3
-3 is a negative number​

 

Output 3 :
Enter a number:
100
100 is a positive number​