0

How to write a program using ternary operator in C++?

show the way to make a program to find whether the given number is odd or even using ternary operator.

20th Aug 2018, 4:48 PM
MADE OF GOD
MADE OF GOD - avatar
2 ответов
+ 1
thanks
5th Sep 2018, 1:14 AM
MADE OF GOD
MADE OF GOD - avatar
0
MADE OF GOD below is syntax for ternary operator : (condition) ? (code to be executed if condition is true ) : (code to be executed if condition is false) let me give you example: int a = 10; int b = 20; int c = a<b ? a : b ; with this, c becomes 10... if a is 5 and b is 3, c becomes 3 Odd or even can be checked with modulo by 2... Hope with this, you will be able to do it
20th Aug 2018, 4:59 PM
Ketan Lalcheta
Ketan Lalcheta - avatar