C Program to find positive negative or zero using Conditional Operator

Any number that is below zero is a negative number and above zero is a positive number. This program takes a number from console and checks if the number entered is a positive number, negative number or zero. To check this conditional (ternary) operator is used.


void main()
	int number;
	printf("Enter a number:\t");
	scanf("%d", &number);
	(number > 0) ? printf("%d is a positive number\n", number):
	(number < 0) ? printf("%d is a negative number\n", number):
	printf("Number is zero\n");

Output 1

Enter a number:	77
77 is a positive number

Output 2

Enter a number:	-13
-13 is a negative number

Output 3

Enter a number:	0
Number is zero