C++ Program to Check Whether a Number is Positive, Negative or Zero

In this program, we will check the number entered by user is Positive, Negative or Zero. We have used else if-else statement to check a condition. If number is less than 0 then it is negative number, if it is greater than 0 then that is positive number otherwise it is zero.



Source Code
#include<iostream>
using namespace std;

int main()
{
    int no;

    cout<<"Enter a number: ";
    cin>>no;

    if(no>0)
    {
        cout<<"Number is positive";
    }
    else if(no<0)
    {
        cout<<"Number is negative";
    }
    else
    {
        cout<<"Number is zero";
    }
    return 0;
}
Output
Enter a number: 5
Number 5 is positive

Enter a number: -21
Number -21 is negative

Enter a number: 0
Number is zero