53 lines
1.0 KiB
C++
Raw Normal View History

2025-01-29 09:18:27 +01:00
#include <iostream>
#include <conio.h>
using namespace std;
int main() {
int a[] = {5,18,7,9,2,1,11,8,2,3};
2025-01-29 09:37:38 +01:00
int i,k,b,c,max1,max2,max3,n;
2025-01-29 09:18:27 +01:00
n = sizeof(a)/sizeof(a[0]);
max1 = a[0];
k = 0;
for(i=1; i<n; i++) {
if(a[i] > max1) {
max1 = a[i];
k = i;
}
}
cout << "Najwiekszy element: " << max1 << endl;
2025-01-29 09:37:38 +01:00
cout << "Indeks: " << k << endl << endl;
2025-01-29 09:18:27 +01:00
2025-01-29 09:23:04 +01:00
if(k == 0) max2 = a[1];
else max2 = a[0];
2025-01-29 09:37:38 +01:00
b = 0;
2025-01-29 09:23:04 +01:00
2025-01-29 09:18:27 +01:00
for(i=1; i<n; i++) {
if(i!=k && a[i] > max2) {
max2 = a[i];
2025-01-29 09:37:38 +01:00
b = i;
}
}
if(b == 0) max3 = a[2];
else max3 = a[0];
c = 0;
for(i=1; i<n; i++) {
if(i!=k && i!=b && a[i] > max3) {
max3 = a[i];
c = i;
2025-01-29 09:18:27 +01:00
}
}
cout << "Drugi najwiekszy element: " << max2 << endl;
2025-01-29 09:37:38 +01:00
cout << "Indeks: " << b << endl;
cout << endl;
cout << "Trzeci najwiekszy element: " << max3 << endl;
cout << "Indeks: " << c << endl;
2025-01-29 09:18:27 +01:00
system("pause");
return 0;
}