Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- int a[7] = {13, 6, 2, 15, 4, 7, 1};
- int n = 7;
- int max;
- int max_pos;
- for (int i = 0; i < n; ++i) { // possible mistake
- max = a[0]; //possible mistake
- max_pos = 0; //possible mistake
- for (int j = 1; j < i - 1; ++j) {
- if (a[j] > max) {
- max = a[j];
- max_pos = j;
- }
- }
- if (i != max_pos) {
- int temp = a[i];
- a[i] = a[max_pos];
- a[max_pos] = temp;
- }
- }
- for (int s : a) {
- cout << s << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement