Advertisement
Guest User

Untitled

a guest
Aug 26th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3. Online C++ Compiler.
  4. Code, Compile, Run and Debug C++ program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <iostream>
  10.  
  11. using namespace std;
  12.  
  13. int main()
  14. {
  15. int n;
  16. cin >> n;
  17. int a[n];
  18. int indexMin = 0, amountMin;
  19. cin >> a[0];
  20. amountMin = a[0];
  21. for(int i = 1; i < n; i++){
  22. cin >> a[i];
  23. if(a[i] < amountMin){
  24. amountMin = a[i];
  25. indexMin = i;
  26. }
  27. }
  28.  
  29. int b;
  30. b = a[0];
  31. a[0] = a[indexMin];
  32. a[indexMin] = b;
  33.  
  34. for(int i = 0; i < n; i++){
  35. cout << a[i] << " ";
  36. }
  37.  
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement