Topic: C Program to Check Positive Negative

Q: Write a C Program to use simple if statement to check positive negative or zero

## How to check for positive number

A number is positive if it is greater than 0 (zero). Use simple if statement.

if (number > 0)

printf(“Number is positive”);

### What is the condition for negative number

Use simple if statement to check whether number is negative. Note that a negative number is less than zero.

if (number < 0)

printf(“Number is negative”);

Similarly use simple if statement to check for zero:

if (number == 0)

printf(“Number is Zero”);

The source code for program to check a number for positive, negative or zero:

/*Input a number. check it for positive negative or zero using only simple if statements */ #include<stdio.h> #include<math.h> int main() { int number; printf("Enter a number to check for positive,negative,zero:"); scanf("%d",&number); if(number>0) printf("%d is Positive",number); if(number<0) printf("%d is Negative",number); if(number==0) printf("Number is Zero"); return 0; }

2,669 total views, 5 views today