C program to check positive, negative or zero

In this example, We take one integer input from user and check inputted number is positive or negative or zero.

Program to check positive, negative or zero :

Logic of this program is simple. First this program checks number is greater than zero or not. If number is greater than zero then it prints Positive otherwise program checks number is less than zero or not. If number is less then zero then it prints Negative otherwise it prints Number is zero.

Example :

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

Output :

	
        //Output :- 1
		Enter a number:
		50
		50 is a positive number
		//Output :- 2
		Enter a number:
		-120
		-120 is a negative number
	

Share your thoughts

Ask anything about this examples