- Get link
- X
- Other Apps
The ternary operator is a shortcut way to write if-else code.
#include <stdio.h>
int main(){
int a;
printf("Enter a number: ");
scanf("%d", &a);
//using ternary operator
//structure: exp1 ? exp2 : exp3;
a%2 == 0 ? printf("Even number") : printf("Odd number");
// if(a%2 == 0){
// printf("Even number");
// }
// else{
// printf("Odd number");
// }
return 0;
}