Program to Check Whether a Number is Positive or Negative - ( C Programs )
Example:
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num > 0)
printf("%d is a positive number", num);
else if (num < 0)
printf("%d is a negative number", num);
else
printf("0 is neither positive nor negative");
return 0;
}
Output:
Enter a number: 5
5 is a positive number
Explanation:
This program checks whether a given input number is positive, negative or zero and then returns the corresponding output. It works by taking in an integer input from the user using the scanf() function and then checking the number using a series of if-else statements. If the number is greater than zero, it's considered positive, if it's less than zero it's considered negative and if it's equal to zero then it's neither positive nor negative.
Use:
This program can be used in various scenarios where there's a need to check whether a number is positive or negative. For example, it can be used in financial calculations, data analysis, and other mathematical operations.
Summary:
In this program, we learned how to check whether a number is positive or negative using if-else statements and the scanf() function. This basic concept can be applied in a variety of real-world scenarios that involve numerical calculations.