Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6. int a[7] = {13, 6, 2, 15, 4, 7, 1};
  7. int n = 7;
  8. int max;
  9. int max_pos;
  10. for (int i = 0; i < n; ++i) { // possible mistake
  11. max = a[0]; //possible mistake
  12. max_pos = 0; //possible mistake
  13. for (int j = 1; j < i - 1; ++j) {
  14. if (a[j] > max) {
  15. max = a[j];
  16. max_pos = j;
  17. }
  18. }
  19. if (i != max_pos) {
  20. int temp = a[i];
  21. a[i] = a[max_pos];
  22. a[max_pos] = temp;
  23. }
  24. }
  25.  
  26. for (int s : a) {
  27. cout << s << " ";
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement