Develop a Program in C to Check If a Number is Positive, Negative, or Zero
Goal:
The goal of this program is to create a simple tool that can determine whether a certain number is positive, negative or zero. Using the if-else statement in C, the program effectively categorizes the input number by its value.
Objective:
The objective of this program is to provide a basic understanding of conditional statements and their use in determining the sign of a number. By checking whether a number is positive, negative or zero, users can understand the concept of decision making in programming and how to use it to perform certain actions based on different situations.
Agenda:
1. Ask the user to input a number.
2. Use if-else statements to check whether the input number is positive, negative, or zero.
3. Display the range to which the number belongs (positive, negative or zero).
4. Explain the process of classifying numbers and the role of if-then statements in making conditional decisions.
5. Discuss the importance of number classification in programming and its real-life applications.
Real-life applications:
Number classification is a fundamental concept in programming with various real-life applications. Some examples include
1. Financial Analysis: In financial analysis and accounting, determining the sign of numbers is crucial for calculating profits, losses, and financial trends. By classifying numbers as positive, negative, or zero, financial analysts can make informed decisions and projections.
2. Temperature Monitoring: In meteorology and climate science, classifying temperature readings as positive, negative, or zero is essential for analyzing weather patterns and trends. By categorizing temperature values, meteorologists can interpret data accurately and predict weather conditions.
3. Inventory Management: In supply chain management and inventory control, classifying inventory levels as positive, negative, or zero helps in tracking stock levels, identifying shortages, and managing orders efficiently. By categorizing inventory numbers, businesses can optimize their supply chain operations.
C program to check if a number is positive, negative, or zero using if-else statements.
/* C language program to check if a number is positive, negative
or zero using if-else statements.*/
#include <stdio.h>
int main()
{
int number;
// Input from user
printf("Enter a number\n ");
scanf("%d", &number);
// Check if number is positive, negative, or zero
if (number > 0) {
printf("%d is a positive number.\n", number);
}
else if (number < 0)
{
printf("%d is a negative number.\n", number);
}
else {
printf("The number is zero.\n");
}
return 0;
}
Output
Enter a number:
-90
-90 is a negative number.