Skip to content

Instantly share code, notes, and snippets.

@mihids
Last active August 29, 2015 14:01
Show Gist options
  • Save mihids/831c4764f9c7d3b8432b to your computer and use it in GitHub Desktop.
Save mihids/831c4764f9c7d3b8432b to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int main()
{
int numbers[] = {11,21,13,41,9,10,29,2,12,0,12};
int highest = numbers[0];
int second_highest = numbers[1];
if (highest < second_highest) { // if all numbers are positive then u can do int second_highest = 0;
int temp = highest;
highest = second_highest;
second_highest = temp;
}
for (int i = 1; i <11; i++) {
if (numbers[i] >= highest) {
second_highest = highest;
highest = numbers[i];
} else if (numbers[i] >= second_highest) {
second_highest = numbers[i];
}
}
cout<<"The second highest number is : "<<second_highest<<endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment