Largest of three Number using Ternary Operator in C

In computer science, a ternary operator is an operator that takes three arguments. The arguments and result can be of different types, featuring a ternary operator “?:” which defines a conditional expression.

Ternary operators work like if-else , (Condition)?(if true return this statement):(if false return this statement) see below image

Ternary Operator C

#include<stdio.h> int main() { int a, b, c, largest; printf("Enter three numbers: "); scanf("\%d \%d \%d",&a, &b, &c); largest=(a>b)? (a>c)?a:c : (b>c)?b:c; printf("Largest Number is: \%d",largest); return 0; } 


C program for ternary operator

Thank you for reading.

Tweet your queries and feedback to @PsychoCodes or leave a message on our Facebook page. You can also comment your questions below.

Also, don’t forget to subscribe to our Newsletter.

If you like this article, then please share it and help us grow.

Preorder and Postorder Traversal of binary tree in Python
02 September 2018

Binary Tree in Python
02 September 2018

Image Sharpening by High Pass Filter using Python and OpenCV
17 August 2018

Explaining Register variables in C with examples
17 August 2018

C program to generate all combinations of N-Bit Binary String
10 July 2018

Data Autosave System using PHP, MySQL and AJAX
06 July 2018

Понравилась статья? Поделиться с друзьями:
Добавить комментарий