#
C++ Program To Check Number Is Positive Or Negative

**Problem:- **Write A C++ Program To Check Number Is Positive Or Negative. The number should be Entered Through User Then program Print the Output.

**Logic:-** As we know that if a number is greater than 0 ( Zero ) Than number is positive and if a number is Less than 0 ( Zero ) than a number is Negative and else number is equal to zero then an entered number is Zero or equal to zero. Below is an explanation of the problem with an example. For this type of problem, there maybe maximum 3 cases, all cases are given below.

**Case 1:- **Either number is greater than zero (Number is Positive).
**Case 2:-** Either number is less than zero (Number is Negative).
**Case 3:-** or number is equal to zero (Number is Equal to Zero).

**Example:- **

**Case 1:- **If a number is greater than zero the number is positive let's take an example assume the number is 20 then compare number 20 to zero definitely number is greater than zero so the program will print "Entered number is the Positive number".

int a; // 'a' is a number entered by user.
if(a>0)
{
cout<<"Number Is Positive:\n";
}

**Case 2:-** If a number is less than zero the number is negative let's take an example assume the number is -20 then compare number -20 to zero definitely number is less than zero so the program will print "Entered number is the Negative number".
int a; // 'a' is a number entered by user.
if(a<0)
{
cout<<"Number Is Negative:\n";
}

**Case 3:-** If a number is equal to zero the number is Zero let's take an example assume the number is 0 (Zero) then compare number 0 (Zero) to Zero definitely number is equal to zero so the program will print "Entered number is Zero".

int a; // 'a' is a number entered by user.
if(a==0)
{
cout<<"Entered Number Is Zero:\n";
}

**See Also:-** C Program To Check Number Is Positive Or Negative

**Solution:- **

#include<iostream>
using namespace std;
int main()
{
int a;
cout<<"Enter The Number You Want To Check : \n";
cin>>a;
if(a<0)
{
cout<<"Number Is Negative:\n";
}
else if(a>0)
{
cout<<"Number Is Possitive:\n";
}
else
{
cout<<"You Enter Zero :\n";
}
return 0;

}

**See Also:- **Java Program To Check Number Is Positive Or Negative

**Output:-**

**You May Also Like:-**

### Share This Article With Your Friends

#### Don't Miss Another Article

Join over **24,000+** people who get FREE and fresh content every month from this Blog. I Respect Privacy, You're Safe! No Spam!

Recommended Posts For You

#### Ghanendra Yadav

Hello, I Am **Ghanendra Yadav** Owner of This Blog, I am professional Blogger and Programmer. I Love Programming, Logo Making, And Banner Designing. My Highest Qualification is MCA From **NIT Warangal**. You Can Find Me On Social Media Through Below Link And If You Have Any Query Related To Programming And Other Subject Comment Below or You Can Mail Me I Will Try To Answer Within 24 Hours
Email:-
**yghanendra@student.nitw.ac.in**

## No comments:

## Post a Comment