How to find greatest of (2 or 3) number using switch?
CODE
How to find greatest of (2
or 3) number using switch?
// Write a program
to find greatest of 2 numbers if choice is 1 and find greatest of 3 numbers if
choice is 2…
int
main()
{
int choice,a,b,c;
printf("\n enter choice(1,2):");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\n enter the value of a
and b:");
scanf("%d%d",&a,&b);
if(a>b)
printf("\n a is
greatest");
else
printf("\n b is
greatest");
break;
case 2:
printf("\n enter th value of
a,b,c:");
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{
if(a>c)
printf("\n a is
greatest");
else
printf("\n c is
greatest");
}
else
if(b>c)
printf("\n b is
greatest");
else
printf("\n c is
greatest");
break;
default:
printf("\n wrong choice");
}
}
Output:
enter choice(1,2): 2
enter th value of a,b,c:
78
45
56
a is greatest
How to find greatest of (2 or 3) number using switch?
Reviewed by Unknown
on
December 31, 2018
Rating:
No comments:
If you have any doubt or query ,comment below: