Find Second largest number using nested if-else:
#include <stdio.h>
int main()
{
int a,b,c,second;
printf("Enter three numbers ");
scanf("%d%d%d",&a,&b,&c);
if(a>b&&a>c)
{
if (b>c)
second=b;
else
second=c;
}
if(b>a&&b>c)
{
if (a>c)
second=a;
else
second=c;
}
if(c>a&&c>b)
{
if(a>b)
second=a;
else
second=b;
}
printf("second largest number :%d",second);
getch();
Input: 5, 3, 4
Output: 4
No comments:
Post a Comment