Write a C Program to find the Largest Number

Write a C program to find the largest number from three numbers using conditional operators in the C programming Language. Make a program in the C programming language. Solution of the Program is as follows –

/*Write a C program to find the largest number among three numbers using conditional operator */

void main()
       int a,b,c,big;
       printf("\nEnter 3 numbers:\n");
       scanf("%d %d %d",&a,&b,&c);
       printf("\nThe biggest number is: %d",big);

a = 10
b = 15
c = 12

big=(a>b && a>c ?a : b>c ?b : c);

=> Condition 1 = a>b && a>c ? a
=10>15 && 10>12 ? a – False

=> Condition 2 = b>c ? b
= 15>12 ? b – True

The condition two i.e 15>12 ? b is true. Therefore the 3rd condition will not be evaluated and variable b will be assigned to variable big and hence we have found the biggest number among three numbers and the output will be printed on the screen.

The biggest number is 15

yashan has written 69 articles

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>