## C program to check whether a number is positive, negative or zero

Write a C program to check positive, negative or zero using simple if or if else. C program to input any number from user and check whether the given number is positive, negative or zero. Logic to check negative, positive or zero in C programming.

#### Logic to check positive, negative or zero

Logic of this program is simple if you know basic maths. Let us have a quick look about number properties.

1. A number is said negative if it is less than 0 i.e. num < 0.

2. A number is said positive if it is greater than 0 i.e. num > 0.

We will use the above logic inside if to check number for negative, positive or zero. Step by step descriptive logic to check negative, positive or zero.

1. Input a number from user in some variable say num.

2. Check if(num < 0), then number is negative.

3. Check if(num > 0), then number is positive.

4. Check if(num == 0), then number is zero.

Let us code solution of the program.

#### Program to check positive, negative or zero using simple if

```

/**
* C program to check positive negative or zero using simple if statement
*/

#include

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;
}
```

The above approach is easiest way to tackle the problem. However, you might think why check three conditions. Instead we can write the above code with two conditions. First check condition for positive number, then if a number is not positive it might be negative or zero. Then check condition for negative number. Finally if a number is neither positive nor negative then definitely it is zero. There is no need to check zero condition explicitly.

Let us re-write our code.

#### Program to check positive, negative or zero using if...else

```

/**
* C program to check positive negative or zero using if else
*/

#include

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
```
```
Recommended posts

Loop programming exercises index.
Basic programming exercises index.
If else programming exercises index.
Array programming exercises index.
String programming exercises index.
Pointer programming exercises index.
Star Patterns exercises index.
Number Patterns exercises index.
alphabet Patterns exercises index.
series program exercises index.

```