How to write C program to find Positive or Negative Number or zero using If Else Statement, Else If Statement and Conditional Operator with an example.

If the number is greater than 0, then the given number is positive, and if it is less than 0, then it is a negative number. If the number is equal to 0, then the given number is 0.

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

This program lets the user enter any number, and then this c program 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:**

In this program to find Positive or Negative Number, First, if condition checks whether the given number is greater than or equal to 0.

- If the condition fails, then the given number will be negative.
- And, 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. Else the value we entered is 0.

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

This program lets the user 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 C program to find Positive or Negative Number is structured as if the first condition fails, it will traverse to the second condition. If both the conditions fail, else statement will execute. Let’s see the working principle of both the conditions below

Checks whether the given number is greater than 0. If this condition is true, the given value is a positive number.*First Condition(*if (number > 0))*:*Checks whether the given number is less than 0. If this condition is true, it is a negative number*Second condition(*else if (number < 0))*:*- If both the above conditions fail, the number is equal to 0.

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

This program lets the user enter any number. Next, this c program checks whether the given value is 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**

Within this C program to find Positive or Negative Number, Let us look closer into conditional operator in the above code. Here we used a 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 the first statement will execute. And, if it fails then it will check the second condition which is after the **:** symbol (number < 0).

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