Check Positive Or Negative Number using CPP
- Home
- Tutorials
- CPP
- CPP Programs
- If Else Statement
- Program
Source Code
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
// Variable Declaration for input
int n;
// Taking input in Variable n
cout<<"Enter Number: ";
cin>>n;
if(n >= 0)
cout<<"Positive\n";
else
cout<<"Negative\n";
return 0;
}
Output
Working
This program defined to check number either positive or negative. For this purpose we declare a variable n of type int to get input from user. After taking input we use selection statement to check.
Whether given number is greater than 0 or not.If number is greater than or equal to zero then it will print positive otherwise it will print negative.