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:

  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. double number;
  6. cout << "Enter a number: ";
  7. cin >> number;
  8. // true if the given number is less than 0
  9. if (number < 0.0)
  10. cout << "It is a negative number.";
  11. // true if the given number is greater than 0
  12. else if ( number > 0.0)
  13. cout << "It is a positive number.";
  14. // if both the test expression is false
  15. else
  16. cout << "It is 0";
  17. return 0;
  18. }

Output:

Enter a number: -9
It is a negative number.