Check If A Number Is Positive Or Negative Using C++

What we are going to see through this article is we will see in detail about Check If A Number Is Positive Or Negative Using C++. A number is said to be positive if it is greater than zero and it is said to be negative if it is less than zero. A number can be checked for zero, positive and negative using if, if-else, nested if-else, and short-hand if-else statements.

Problem Solution

1. The program takes a number.
2. It is checked if it is positive or negative.
3. The result is printed.
4. Exit.

           Examples

Input 1 : 67
Output 1 : 67> 0. So 67 is a Positive number

Input 2 : -67
Output 1 : -67< 0. So 67 is a Negative number
Check If A Number Is Positive Or Negative Using C++

Check if a Number is Positive or Negative using C++

#include<iostream>
using namespace std;
int main ()
{
    int num;
    cout << "Enter the number to be checked : ";
    cin >> num;
    if (num >= 0)
        cout << num << " is a positive number.";
    else 
        cout << num << " is a negative number.";
    return 0;
}

Read Also: Calculate Grade Of Student Using C++

Output

Case 1 :
Enter the number to be checked : -8
-8 is a negative number.
 
Case 2 :
Enter the number to be checked : 0
0 is a positive number.
 
Case 2 :
Enter the number to be checked : 125
125 is a positive number.

Final Words

What we learned through this article is Check If A Number Is Positive Or Negative Using C++. Also if you have any doubts please leave a comment via the comment box. And we ask that you benefit everyone who shared this article with your friends.

Leave a Comment