i am currently having problem getting largest values from an array, here is my code:
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int a[10],max=0,j,secondbig=0;
for(int i=0;i<10;i++)
{
cin>>a[i];
}
max = a[0];
for(int i=0;i<10;i++)
{
if(a[i]>max){
max=a[i];
j=i;
}
}
secondbig=a[10-j-1];
for(int i=0;i<10;i++)
{
if(secondbig <a[i] && j != i)
secondbig =a[i];
}
cout<<max<<"\n"<<secondbig;
return 0;
}
What i want to do is to first get maximum value from an array and then leave one array value and then get second largest value and same for third largest value, for example :
200
100
50
300
400
500
600
700
800
900
If in the above test values 900 is the largest value then the subsequent second and third largest value should be 700 and 500, is there anyway to do that?