C++ program to check the given number is positive or negative
gd.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
godarda@gd:~$ g++ gd.cpp
godarda@gd:~$ ./a.out Enter a number -3.14 Entered number is negative godarda@gd:~$ ./a.out Enter a number 0 Entered number is zero godarda@gd:~$
Comments and Reactions