C program to find the largest of three numbers using ternary operator

By
Advertisement
A Ternary operator is acts as a selection statement also. That is depending on the condition we can provide, we make a selection. For example


              Example: ( a>b)a:b then depending on the condition a>b we select one of the two values.


The following program finds the biggest of three numbers using Ternary operator


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# include <stdio.h>
      void main()
    {
    int a, b, c, big ;
    clrscr();
    printf(" welcome to www.tutorialTpoint.net\n");
    printf("Enter three numbers :\n ") ;
    scanf("%d %d %d", &a, &b, &c) ;
    big = a > b ? (a > c ? a : c) : (b > c ? b : c) ;
    printf("\nThe biggest number is : %d\n", big) ;
    getch();
    }


After successful execution of the above program it produces the following out

 

0 comments:

Post a Comment