Find 1st ,2nd and third Minimum Number in Array Using C++
========================================================================
#include<iostream>
using namespace std;
main()
{
int arr[5]={88,99,11,12,6};
int min=arr[0],min2=arr[0],min3=arr[0];
for(int i=0;i<5;i++)
{
if(arr[i]<min)
{
min=arr[i];
}
}
cout<<"1st Minimum Nmumber = "<<min;
if(min2==min)
{
min2=arr[1];
}
for(int i=0;i<5;i++)
{
if(arr[i]>min)
{
if(arr[i]<min2)
{
min2=arr[i];
}
}
}
cout<<"\n2nd Minimum Number = "<<min2<<endl;
if(min3==min||min3==min2)
{
min3=arr[2];
}
for(int i=0;i<5;i++)
{
if(arr[i]>min2)
{
if(arr[i]<min3 )
{
min3=arr[i];
}
}
}
cout<<"3rd Minimum Number = "<<min3;
}
========================================================================
OutPut :
Code By : Kabeer Hussain
0 comments:
Post a Comment