Advertisement
Vtrhugo

Lista 6 - 1

May 24th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int i, j, aux, n=8;
  6.     int vetor[n] = { 4, 2, 6, 8, 1, 3, 7, 5 };
  7.  
  8.     for(i=1; i<n; i++){
  9.         for (j=0; j<n-i; j++){
  10.             if (vetor[j] > vetor[j+1]){
  11.                 aux = vetor[j];
  12.                 vetor[j] = vetor[j+1];
  13.                 vetor[j+1] = aux;
  14.             }
  15.         }
  16.     }
  17.     cout << "Vetor Ordenado: \n";
  18.     for (i=0; i<n; i++)
  19.         cout << "  " << vetor[i];
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement