Task: Read a number and classify it as positive, negative, or zero using nestedif-else statements. Print only the category.
/* Program: Sign of a Number (nested if-else) — U1 What it does: - Reads a real number x. - Uses nested if-else to print "positive", "negative", or "zero". Notes: - Using double allows inputs like 3.14 or -2.5 as well as integers. - In C, -0.0 compares equal to 0.0, so it will be reported as "zero".*/
#include <stdio.h>
int main(void) {
double x;
printf("Enter a number: ");
if (scanf("%lf", &x) != 1) {
printf("Invalid input. Please enter a numeric value.\n");
return 0;
} /* Nested if-else structure for classification */
if (x >= 0.0) {
if (x == 0.0) {
printf("zero\n");
} else {
printf("positive\n");
}} else {
printf("negative\n");
} /* Examples:
Input: 7 -> positive Input: -3.25 -> negative Input: 0 -> zero*/
return 0;
}