- The program first declares a variable
num
to store the user input. - It then prompts the user to enter a number using the
printf()
andscanf()
functions. - An
if-else
statement is used to check whether the number is positive, negative or zero. If the number is greater than 0, the program prints that the number is positive. If the number is less than 0, the program prints that the number is negative. If the number is equal to 0, the program prints that the number is zero. - Finally, the program returns 0 to indicate successful execution.
#include <stdio.h> int main() { int num; printf("Enter a number: "); scanf("%d", &num); if (num > 0) { printf("%d is positive.", num); } else if (num < 0) { printf("%d is negative.", num); } else { printf("Number is zero."); } return 0; }
OUTPUT
Enter a number: 7
7 is positive.
Menu