Conditional Operators

6. Conditional Operators
Conditional Operator is ? :.Before the question mark we write the condition. After the question mark it show the result if the condition is true else if the condition is fail it executes after the colon result.
Syntax 1:- (<Condition>)?<truevalue>:<falsevalue>;
Conditional operator gives the result if the condition is true or false.

Ex 1: Write a program to findout the given number is even or odd.



output












Ex 2: Write a program to check the given age is eligible for vote or not.












output












Syntax 2:- (<Condition1>)?<truevalue>:(<Condition2>)?<truevalue>:<falsevalue>;

Write a program to check whether the given number is positive or negative or zero.











output



Syntax 3:- variable=(<Condition>)?<truevalue>:<falsevalue>;

Write a program to findout the biggest number among the given number.














(or)














output



No comments:

Post a Comment