4
I have the following code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, cases = 1, a[3];
cin >> n;
while(cases != n + 1)
{
cin >> a[0] >> a[1] >> a[2];
sort(a, a + 2);
cout << "Sorted array: " << a[0] << " " << a[1] << " " << a[2] << endl;
cout << "Case " << cases << ": " << a[1] << endl;
cases++;
}
return 0;
}
For cases with the entries: 30 25 15, the array is: 25 30 15.
That would be a bug, or I was the one who implemented it wrong?
I understood, I used + 2, because I thought it worked like this: a + 0 -> first position a + 1 -> second position a + 2 -> third position (for programming marathons), do you have any tips for me to improve my codes? Thank you!
– Emanuel Huber
Then you have to ask specific questions.
– Maniero