Example
Input
Input number: 23
Output
23 is positive
Program to check positive, negative or zero using simple if
/**
* C program to check positive negative or zero using simple if statement
*/
#include <stdio.h>
int main()
{
int num;
/* Input number from user */
printf("Enter any number: ");
scanf("%d", &num);
if(num > 0)
{
printf("Number is POSITIVE");
}
if(num < 0)
{
printf("Number is NEGATIVE");
}
if(num == 0)
{
printf("Number is ZERO");
}
return 0;
}
Program to check positive, negative or zero using if...else
/**
* C program to check positive negative or zero using if else
*/
#include <stdio.h>
int main()
{
int num;
/* Input number from user */
printf("Enter any number: ");
scanf("%d", &num);
if(num > 0)
{
printf("Number is POSITIVE");
}
else if(num < 0)
{
printf("Number is NEGATIVE");
}
else
{
printf("Number is ZERO");
}
return 0;
}
/*
Output :
Enter any number: 10
Number is POSITIVE
*/