C Program to Demonstrate Ternary Operator
Write C code to demonstrate the use of ternary operator
//Write a c program to implement ternary operator #include <stdio.h> int main() { int age; printf("Enter your age :--> "); scanf("%d", &age); (age >= 18) ? printf("You are eligible to vote") : printf("You are not eligible to vote"); //if age greater than 18 then eligible else not return 0; }
Outpu:
Run 1:
Enter your age :--> 56
You are eligible to vote
Run 2:
Enter your age :--> 14
You are not eligible to vote