C++ Program to Check if a Number is Positive, Negative or Zero.














































C++ Program to Check if a Number is Positive, Negative or Zero.



In the below program, to find whether a Number is positive, negative or zero.
First the number is taken as input from the user.
Then number is checked for positive using if-else statement and >, < and == operators.


#include<iostream>
using namespace std; int main() { int n; cout << " Enter the Number : "; cin >> n; // Check if Number is Zero if( n == 0) cout << " Number is Zero "; // Check if Number is Postive or Negative if(n > 0) { cout << " Number is Positive "; } else { cout << " Number is Negative "; } return 0; }

INPUT : 0
OUTPUT : Number is Zero

INPUT : -9
OUTPUT : Number is Negative

INPUT : 5
OUTPUT : Number is Positive


Comments