order + update

This commit is contained in:
Sebastian Ranoszek 2025-01-29 09:37:38 +01:00
parent 61570e1c63
commit eee0a5263e
6 changed files with 27 additions and 2 deletions

7
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,7 @@
{
"files.associations": {
"*.embeddedhtml": "html",
"iostream": "cpp",
"ostream": "cpp"
}
}

View File

@ -4,7 +4,7 @@ using namespace std;
int main() { int main() {
int a[] = {5,18,7,9,2,1,11,8,2,3}; int a[] = {5,18,7,9,2,1,11,8,2,3};
int i,k,max1,max2,n; int i,k,b,c,max1,max2,max3,n;
n = sizeof(a)/sizeof(a[0]); n = sizeof(a)/sizeof(a[0]);
max1 = a[0]; max1 = a[0];
@ -17,18 +17,36 @@ int main() {
} }
cout << "Najwiekszy element: " << max1 << endl; cout << "Najwiekszy element: " << max1 << endl;
cout << "Indeks najwiekszego elementu: " << k << endl; cout << "Indeks: " << k << endl << endl;
if(k == 0) max2 = a[1]; if(k == 0) max2 = a[1];
else max2 = a[0]; else max2 = a[0];
b = 0;
for(i=1; i<n; i++) { for(i=1; i<n; i++) {
if(i!=k && a[i] > max2) { if(i!=k && a[i] > max2) {
max2 = a[i]; max2 = a[i];
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;
} }
} }
cout << "Drugi najwiekszy element: " << max2 << endl; cout << "Drugi najwiekszy element: " << max2 << endl;
cout << "Indeks: " << b << endl;
cout << endl;
cout << "Trzeci najwiekszy element: " << max3 << endl;
cout << "Indeks: " << c << endl;
system("pause"); system("pause");
return 0; return 0;