Advertisement
RafaelMonitor

Exercício de ordenação de vetor (Bubble-Sort)

Apr 29th, 2019
562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.50 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.     printf("\nEste programa ordena o vetor {7,3,8,2,0} em ordem crescente");
  7.     int vetor[5]={7,3,8,2,0}, i, j, aux;
  8.     for(j=0;j<4;j++)
  9.     {
  10.         for(i=0;i<4;i++)
  11.         {
  12.             if (vetor[i]>vetor[i+1])
  13.             {
  14.                 aux=vetor[i];
  15.                 vetor[i]=vetor[i+1];
  16.                 vetor[i+1]=aux;
  17.             }
  18.         }
  19.     }
  20.     for(i=0;i<5;i++)
  21.     {
  22.         printf("\n%d",vetor[i]);
  23.     }
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement