13.Develop a program in C language to check if a number is positive, negative, or zero using 'if-else' statements.
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 categorize the input number by its value.
Objective:
The objective of this program is to provide a basic understanding of conditional sentences 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.
a program in C language 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.
Explanation
1. We include the necessary header file stdio.h for input/output operations.
2. In the mai function, we declare an integer variable number to store the input number.
3. We prompt the user to enter a number using printf and read the input using scanf.
4. We use if-else statements to check the value of the input number:
- If the number is greater than 0, it is considered positive.
- If the number is less than 0, it is considered negative.
- If the number is equal to 0, it is considered zero.
5. Based on the condition met, the program prints the appropriate message indicating whether the number is positive, negative, or zero.
6. Finally, the program returns 0 to indicate successful execution.
Previous :-->> 12.Implement a program C language to check if a character is an alphabet, digit, or special character using 'if-else' statements.
NEXT:
14.Write a program in C to find the maximum of three numbers using nested 'if-else' statements.
-->>ALL Conditionl statements Programs