C Program to use simple if statement to check positive negative or zero

By | June 29, 2019

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”);

The source code for C program to check a number for positive, negative or zero using simple if statement

The source code for C program to check a number for positive, negative or zero using simple if statement

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 C program to check a number for positive, negative or zero using simple if statement:

/*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;
}

Leave a Reply

Your email address will not be published. Required fields are marked *