Hai D. answered 04/13/20
Software Engineer at Microsoft with MS in Computer Science
1 #include <iostream>
2 #include <vector>
3 using namespace std;
4
5 int main()
6 {
7 int n, i, j, temp, k;
8
9 cout << "Enter a number of integers: ";
10 cin>>n;
11
12 vector<int> arr;
13 for(int i = 0;i<n;i++) {
14 cout << "Enter number" << i+1 << ": ";
15 cin>>k;
16 arr.push_back(k);
17 }
18
19 for (i = 0; i < 2; i++) { // Sorting by bubble sort
20 for (j = 0; j < n - i - 1; j++) {
21 if (arr[j] < arr[j + 1]) {
22 temp = arr[j];
23 arr[j] = arr[j + 1];
24 arr[j + 1] = temp;
25 }
26 }
27 }
28
29 cout<<arr[n-1]<<" "<<arr[n-2]<<endl;
30 return 0;
31 }