MASIGNASUKAv102
6510051498749449419

C++ Program to Check Given Number is Positive or Negative - Learn With AVRK

Add Comments
Saturday, August 28, 2021

C++ Program for Checking a Given Number is Positive or Negative

Here in this example we are going to learn how to check that the entered number is negative or positive.

Loading...

You should have knowledge of following C++ programming topics for better understanding -

This program takes an input from the user as an integer value and checks that the number entered is positive or negative or zero.


Checking Positive or Negative Value Using if-else -

#include<iostream> 
using namespace std;
int ()
{
int x;
cout<<"Enter a number: ";
cin>>x;
    if(x<0)
    {
     cout<<"You entered a negative number.";
    }
    else if(x==0)
    {
     cout<<"You entered 0";
    }
    else
    cout<<"You entered a positive number.";
return 0;
}

Output 1 -

Loading...


Output 2 -

Loading...


Output 3 -

Loading...

Also check out this : Temple Pattern Program in C++ ( With Source Code ) - Learn With AVRK
Learn With AVRK

Learn With AVRK