Check number is positive, negative or zero in C
if else if - Question 2
In this question, we will see how to input a number and check if it is a positive number or a negative number or a zero in C programming using the if else if statement. To know more about if else if statement click on the if else if statement lesson.
Q2) Write a program in C to input a number and check if it is a positive number or a negative number or a zero.
Program
#include <stdio.h>
#include <conio.h>
int main()
{
int n;
printf("Enter a number ");
scanf("%d",&n);
if(n>0)
{
printf("Positive number");
}
else if(n<0)
{
printf("Negative number");
}
else
{
printf("Zero");
}
return 0;
}
Output
Enter a number -5 Negative number