C Program to check whether the given integer is positive or negative

June 5, 2021

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.

/* Description: A program to check whether the input
 * integer number is positive or negative. 
 
 */
#include <stdio.h>
 
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 1:
Enter a number: 0 0 is neither positive nor negative
Output 2:
Enter a number: -3 -3 is a negative number

admin