A Program to Check Whether a Number is Positive or Negative or Zero
In this example, we are giving a program which is useful to check whether a number given by the user is positive or negative or zero.
Program to check Positive or Negative or Zero:
#include <iostream>using namespace std;int main(){double number;cout << "Enter a number: ";cin >> number;// true if the given number is less than 0if (number < 0.0)cout << "It is a negative number.";// true if the given number is greater than 0else if ( number > 0.0)cout << "It is a positive number.";// if both the test expression is falseelsecout << "It is 0";return 0;}
Output:
Enter a number: -9 It is a negative number.