To Find First,Second &Third Largest No. From A Given Array

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int f,s,t,a[50],n,i;
cout<<"\n Enter Size Of Array: ";
cin>>n;
cout<<"\n Enter The Array:- ";
for(i=0;i<n;i++)
{
    cin>>a[i];
}
f = a[0];
s = a[0];
t = a[0];
for(i=0;i<n-1;i++)
{
    if(a[i] > f)
     f = a[i+1];
   
}
for(i=0;i<n-1;i++)
{

    if((a[i] > s) && (f > a[i]) )
        s = a[i+1];
}
     for(i=0;i<n-1;i++)
{

     if((a[i] > t) && (f > a[i]) && (s > a[i]))
        t = a[i+1];
}
cout<<"\n The First Largest No. Is" <<f;
cout<<"\n The Second Largest No. Is "<<s;
cout<<"\n The Third Largest No Is."<<t;
getch();
}

Comments