If the number is greater than 0 then the given number is a positive number and if the number is less than 0 then the given number is negative number. If the number is equal to 0 then given number is obviously 0. In this article we will show you, How to write C program to find Positive or Negative Number or zero using If Else Statement, Else If Statement and Conditional Operator with example.

## C program to find Positive or Negative Number using Nested If Condition

This C program lets the user to enter any number and then checks whether the entered value is either positive or negative or zero using Nested If

#include <stdio.h> int main() { int number; printf("Enter any number:\n"); scanf("%d",&number); if (number >= 0) { if (number > 0) printf("%d is Positive Number", number); else printf("You have entered Value zero."); } else printf("%d is Negative Number", number); return 0; }

**OUTPUT:**

Check for Negative Value

Check for Zero

**ANALYSIS:**

First If condition check whether the given number is greater than or equal to 0.

- If the condition fails then given number will be negative number.
- If the condition is true then we have to check whether the number is greater than 0 or not. If the number is greater than 0 then the given number is positive number else the value we entered is 0.

## C program to find Positive or Negative Number using Else If

This program lets the user to enter any number and then checks whether the entered value is either positive or negative or zero using Else If Statement in C.

#include <stdio.h> int main() { int number; printf(" Enter any number:\n "); scanf("%d",&number); if (number > 0) printf("%d is positive number", number); else if (number < 0) printf("%d is a negative number.", number); else printf(" You entered value zero."); return 0; }

**OUTPUT:**

Check for Negative Value

Check for Zero

**ANALYSIS**

Above program is structured as if the first condition fails it will traverse to second condition. If both the conditions fail then, else statement will execute. Letâ€™s see the working principle of both the conditions below

If condition [if (number > 0)] checks whether the given number is greater than 0. If this condition is true then the given value is positive number.*First Condition:*Else If condition [else if (number < 0)] checks whether the given number is less than 0. If this condition is true then the given value is negative number*Second condition:*- If both the above conditions fails then the given number is equal to 0.

## C program to find Positive or Negative Number using Conditional Operator

This program lets the user to enter any number and then checks whether the entered value is either positive or negative or zero using Conditional Operator or Ternary operator

#include <stdio.h> main() { int number; printf(" Enter any number \n"); scanf(" %d ",&number); (number > 0)? printf(" Number is Positive \n"): (number < 0)? printf(" Number is Negative \n"):printf(" Number is zero \n"); return 0; }

**OUTPUT:**

Check for Negative Value

Check for Zero

**ANALYSIS**

Let us look closer into conditional operator in the above code. Here we used nested conditional operator rather than the normal one.

(number > 0)? printf("Number is Positive\n"): (number < 0)?printf("Number is Negative\n"):printf("Number is zero\n");

If the condition (number > 0) is true then first statement will execute. If it fails then it will check the second condition which is after the **:** symbol (number < 0).

- If this condition is true then it will print the first condition printf(“\n number is Negative Number”)
- If this condition is false then printf(“\n number is zero”); will be printed.

Thank you for visiting our Blog