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 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;
}

                        

🖥 Program 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
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.