C++ Program to check whether a number is positive or negative

Program to Check whether a number is Positive or Negative

Here we will discuss how to check whether a number is positive or negative in C++ programming language.

  • A number is positive if it is greater than 0 
  • A number is negative if it is less than 0
  • To check this we use if else statement
  • If the condition  n>0 is true then the number is positive
  • Otherwise the number is negative

Note: 0 is neither positive nor negative   

Find whether a number is positive or negative

 

Algorithm

Step 1. Start

Step 2. Insert the number.

Step 3. If the number is Zero then print “The number is Zero”

Step4: If the number is greater than zero, then print, “The number is Positive”

Step 5. Else print, “The number is Negative”

Step 6. Stop

C++ Progam:

#include <iostream>
using namespace std;
int main()
{
  int n;
  cout<<"Enter a number: "; 
cin>>n; if(n==0) cout<<"The number is Zero";
else if(n>0) cout<<"The number is Positive"; else cout<<"The number is Negative"; }

Output:

Enter a number: 96
The number is Positive