A Program to Check a Number is Positive or Negative

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 <stdio.h>
  2. int main()
  3. {
  4. double number;
  5. printf("Enter a number: ");
  6. scanf("%lf", &number);
  7. // true if the given number is less than 0
  8. if (number < 0.0)
  9. printf("It is a negative number.");
  10. // true if the given number is greater than 0
  11. else if ( number > 0.0)
  12. printf("It is a positive number.");
  13. // if both the test expression is false
  14. else
  15. printf("It is 0");
  16. return 0;
  17. }

Output:

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