C Program to Check Whether the Given Number is Positive Negative or Zero

C Program to Check Whether the Given Number is Positive Negative or Zero

In this article, we are going to discuss how to find C Program to Check Whether the Given Number is Positive Negative or Zero. So let’s start!

To understand this program in a better way you have to know some concepts of C, that are if else conditions. If you know this concept then it will be easy to understand this course. So here in this article, we going to see two examples of this, Let’s discuss them one by one.

C Program to Check Whether the Given Number is Positive Negative or Zero

C Program to Check Whether the Given Number is Positive Negative or Zero

Example 1 :

\ C Program to Check Whether the Given Number is Positive Negative or Zero.

#include<stdio.h>
int main()
{
int num;
printf(“Enter any number:”);
scanf(“%d”, &num);
if(num>0){
printf(“%d is positive”, num);
}
else if(num==0){
printf(“%d is zero “,num);
}
else if(num<0){
printf(“%d is negative”,num);
}
return 0;
}

Output :

Enter any number :

2 is positive.

Step 1: First we take the int type variable to take input from the user.

Step 2: Then first we apply the if condition to check whether the given number is positive or not. If the number is positive then we simply print that, it is positive.

Step 3: If the first condition is false then we move toward our next step in which we check whether our number is zero or not.

Step 4: if the number is neither positive nor zero then we simply move toward our next step. In this step, we simply check whether our number is negative or not.

Step 5: Then we simply get our output.

Example 2 :

#include<stdio.h>
int main(){
int num;
printf(“Enter any number :”);
scanf(“%d”, &num);
if(num >0){
printf(“%d is positive”, num);
}
else if(num<0){
printf(“%d is negative”, num);
}
else{
printf(“%d is zero”, num);
}
return 0;
}

Output

Enter any number: 22

22 is positive

Step 1: First we take the int type variable to take input from the user.

Step 2: Then first we apply the if condition to check whether the given number is positive or not. If the number is positive then we simply print that, it is positive.

Step 3: If the first condition is false then we are moving toward our next step. In that, we check that our number is negative or not if the condition is true then, we simply print that it is negative.

Step 4: if the number is neither positive nor negative then we simply move toward our next step. In that we check whether the number is zero or not, if this condition is true then we simply print it as zero.

In this way, we simply C Program to Check Whether the Given Number is Positive Negative or Zero. I hope this concept is clear to you now. So for now keep learning and keep exploring.