C++ program to check the given number is positive or negative
kw.cpp
#include <iostream>
using namespace std;
int main()
{
    int n;
    cout<<"Enter a number ";
    cin>>n;
    if (n < 0)
    {
        cout<<"Entered number is negative"<<endl;
    }
    else if (n > 0)
    {
        cout<<"Entered number is positive"<<endl;
    }
    else
    {
        cout<<"Entered number is zero"<<endl;
    }
    return 0;
}
Output
kodingwindow@kw:~$ g++ kw.cpp
kodingwindow@kw:~$ ./a.out Enter a number -3.14 Entered number is negative kodingwindow@kw:~$ ./a.out Enter a number 0 Entered number is zero kodingwindow@kw:~$
Advertisement