Home / Programs / Write a program in C to check whether a number given by the user is zero, positive, or negative
Programming Example

Write a program in C to check whether a number given by the user is zero, positive, or negative

👁 1,127 Views
💻 Practical Program
📘 Step by Step Learning
Write a program in C to check whether a number given by the user is zero, positive, or negative

Program Code

#include <stdio.h>
int main()
{
	int x;
	printf("\n ENTER THE NUMBER:");
	scanf("%d", &x);
	if(x > 0)
		printf("x is positive \n");
	else if(x == 0)
			printf("x is zero \n");
		 else
			printf("x is negative \n");
			
    getch();			
	return 0;
}

Output

<b>Output 1:</b>

 ENTER THE NUMBER:12
x is positive

<b>Output 2</b>

 ENTER THE NUMBER:0
x is zero

<b>Output 3</b>

 ENTER THE NUMBER:-12
x is negative 

Explanation

None

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.