C Program to check whether the given integer is positive,negative or zero using Conditional operator

C Program to check whether the given integer is positive,negative or zero using Conditional operator

Write a C Program to check whether the given integer is positive,negative or zero using Conditional/Ternary operator ?:. How to check alphabets using conditional operator in C programming.

Required knowledge

Operators, Data Types in c, Variables in C, Basic input/output

C Program to check whether the given integer is positive,negative or zero using conditional operator

/** * C Program to check whether the given integer is positive, * negative or zero using conditional operator */ #include <stdio.h> #include <conio.h> int main() { int number; clrscr(); /* * Input character from user */ printf("\n Enter first number: "); scanf("%d", &number); /* * If (number>0) then * print number is positive. * else (number<0) then * print number is negative. * else * print number is zero. */ (number>0) ? printf("%d is positive.",number) : (number<0) ? printf("%d is negative.",number) : printf("%d is zero.",number); getch(); return 0; }


Output:
Enter any number:20 20 is positive.




Instagram