Google News
logo
C Program to Check Whether a Number is Positive or Negative
This is a C program to check whether a given integer is positive or negative.
Program :
#include 
 
void main()
{
    int number;
 
    printf("Enter a number \n");
    scanf("%d", &number);
    if (number >= 0)
        printf("%d is a positive number \n", number);
    else
        printf("%d is a negative number \n", number);
}


Explanation :

* Take the integer which you want to check as input and store it in a variable number.
* Using if,else statements check whether the integer is greater or lesser than zero.
* If it is greater than or equal to zero, then print the ouput as “it is a positive number”.
* If it is lesser than zero, then print the ouput as “it is a negative number”.
* Exit.

Output :
Case:1
Enter a number
-10
-10 is a negative number
 
Case:2
Enter a number
45
45 is a positive number