Sunday 26 July 2015

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

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

Note: only a member of this blog may post a comment.

Machine Learning

More

Advertisement

Java Tutorial

More

UGC NET CS TUTORIAL

MFCS
COA
PL-CG
DBMS
OPERATING SYSTEM
SOFTWARE ENG
DSA
TOC-CD
ARTIFICIAL INT

C Programming

More

Python Tutorial

More

Data Structures

More

computer Organization

More
Top