C Program to check Positive Negative or Zero

check-Positive-Negative-or-Zero-program-in-c-language

Description:

We are going to write The Number sign check program in C language, The program going to check Positive Negative or Zero based on the user input number. We will write the program in two different methods one is using the If else statement and the second one is using switch statement.

Expected Output:

As you can see from the above output, The number 43 is positive and -31 is a Negative number.

Pre-Requisite:

It is recommended to know about the decision-making statement like if else condition.

Please go through the following if-else article.

Check Number sign is Positive, Negative or Zero Program in C:

We write this program using the if-else statements or switch statements. We are going to look into these two methods

  1. Check the number sign ( Positive, Negative or Zero) using the if else statements
  2. Check the number sign using a switch statement or switch case

C Program to Check Number sign is Positive, Negative or Zero using if else statements:

Program Explanation:

  • The program will take a number from the user and store it in the variable num.
  • Then we are using the if-else statement for checking if the number is equal to zero using num == 0 comparison operator
  • If the number is not zero, then we will proceed further and check the num > 0 condition. If it is true, Then the num is the Positive Number
  • If the above two conditions are false, Then the given number num is a Negative Number.

Check Number sign Program:

Program Output:

C Program to Check Number sign is Positive, Negative, or Zero using Switch Statement:

Check Positive Negative or Zero Program Explanation:

In the previous method, we used the if else statement to check the number sign. In this method, We are going to use the Switch statement to get the sign of the given number.

  • The program starts by asking the user for the number and we store it in variable num
  • Then we use the Switch Statement to check if the number is equal to or greater than the using num >= 0 condition.
  • If the above condition is True, Then the num is neither a Positive Number of Zero.
    • Now we need to check if the num is Positive number of Zero, To do that, We are going to use another Switch statement with the num == 0 condition, which checks if the num is equal to zero.
    • If above condition is True, Then given number num is Zero.
    • If the above condition is False, Then Number is a positive number, So the Inner Switch case default case is executed and we display the message saying Number is Positive
  • If the above condition is False, Then the given number num is a Negative Number. We can display the output saying given number is Negative.

Check Number Sign Program using Switch Statement:

Program Output:

Example Output 1:

Example Output 2:

Example Output 3:

Venkatesh

Hi Guys, I am Venkatesh. I am a programmer and an Open Source enthusiast. I write about programming and technology on this blog.

You may also like...

2 Responses

  1. […] C Program to Check the Sign of the Number ( Positive, Negative, or Zero) Using Switch Case […]

  2. […] C Program to Check the Sign of the Number ( Positive, Negative, or Zero) Using Switch Case […]

Leave a Reply