#include<stdio.h>
void main()
{
int a, b, c;
printf("Enter value of a, b and c: ");
scanf("%d %d %d", &a, &b, &c);
if(a>b)
{
if(a>c)
{
printf("Largest no.=%d", a);
}
else
{
printf("\nLargest no.=%d", c);
}
}
else if(b>c)
{
printf("\nLargest no.=%d", b);
}
else
{
printf("\nLargest no.=%d", c);
}
}
EXPLANATION:-
#include<stdio.h>
void main()
{
int a, b, c;
printf("Enter value of a, b and c: ");
scanf("%d %d %d", &a, &b, &c);
if(a>b) //check if first no. is greater than second
{
if(a>c) // if first condition gets true, check if the first no is greater than third no.
{
printf("Largest no.=%d", a); // if both upper conditions gets true, it means the first
} no. is the largest of the three
else //the first condition is true and the second is false which means a is greater than b but smaller than c. So, the largest no. will be c.
{
printf("\nLargest no.=%d", c);
}
}
else if(b>c) //The control comes here when the first condition(a>b) is false, i.e, a is not greater than b and if b>c, b will be the largest.
{
printf("\nLargest no.=%d", b);
}
else //The control comes here when (a<b<c) . c will the largest no.
{
printf("\nLargest no.=%d", c);
}
}
0 Comments