C++ Program to check if Number is Positive or Negative

In this programming tutorial we will see the Positive or Negative Number check Program in C++ which will take an input number from the user and will check if the number is positive or negative. If it is positive it will print message saying the entered number is positive otherwise it will print negative. In this program we will be using the if-else control statements.

Positive or Negative Number check Program in C++
#include <iostream>
using namespace std;

int main() {
    int number;
    cout<< "Enter an integer: ";
    cin>> number;
    if ( number >= 0) {
        cout << "You entered a positive integer: "<<number<<endl;
    }
    else {
        cout<<"You entered a negative integer: "<<number<<endl;
    }
    return 0;
}
Output
Enter an integer: -5
You entered a negative integer: -5

Leave a Reply

Your email address will not be published. Required fields are marked *