# CoCubes Coding Question - Second largest Number

### Second largest Number: CoCubes Coding Question

1.  PROBLEM STATEMENT:
You are given a function,
int  FindSecondLargestNumber(int a,int b,int c);
The function takes three integers 'a', 'b','c' as input .Implement the function to find and return the second largest number.

CODING:
int FindSeconLargestNumber(int a,int b,int c);
{

}

#include <stdio.h>

int main()

{
int a,b,c,lar,seclar;

scanf("%d%d%d",&a,&b,&c);

if(a>b)
{
if(a>c)
lar=a;
else
seclar=a;
}

if(b>c)
{
if(b>a)
lar=a;
else
seclar=b;
}
if(c>a)
{
if(c>b)
lar=c;
else
seclar=c;
}
printf("second largest number :%d",seclar);

}

1. Above code does not work.Consider the following code :
int secLargest(int a , int b,int c)
{
int large=0,seclarge=0;
if(a>b)
{
if(a>c)
large=a;
else
seclarge=a;
}
else
{
if(a>c)
seclarge=a;
}
if(b>c)
{
if(b>a)
large=b;
else
seclarge=b;
}
else
{
if(b>a)
seclarge=b;
}

if(c>a)
{
if(c>b)
large=c;
else
seclarge=c;

}
else
{
if(c>b)
seclarge=c;
}

return seclarge;

}

2. Above code does not work.Consider the following code :
int secLargest(int a , int b,int c)
{
int large=0,seclarge=0;
if(a>b)
{
if(a>c)
large=a;
else
seclarge=a;
}
else
{
if(a>c)
seclarge=a;
}
if(b>c)
{
if(b>a)
large=b;
else
seclarge=b;
}
else
{
if(b>a)
seclarge=b;
}

if(c>a)
{
if(c>b)
large=c;
else
seclarge=c;

}
else
{
if(c>b)
seclarge=c;
}

return seclarge;

}