Advertisement
Ivan_sjc

Exercicio booblesort

Apr 3rd, 2013
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.95 KB | None | 0 0
  1.  Leia um vetor de 10 posições e o compacte, ou seja, elimine as posições com valor zero avançando uma posição, com os valores subsequentes do vetor. Dessa forma todos “zeros” devem ficar para as posições finais do vetor.
  2.  
  3.  
  4.  
  5.  
  6.  
  7. #include<stdio.h>
  8. #include<conio.h>
  9. #include<stdlib.h>
  10.  
  11. main(){
  12.        
  13.        
  14.        int vet[10];
  15.        int i;
  16.        int aux;
  17.        int j;
  18.        
  19.        printf("insira dez numeros incluindo 0 \n");
  20.        for (i = 0 ; i<10 ;i++){
  21.            scanf("%d", &vet[i]);
  22.        }
  23.        
  24.        for (j=0 ;j<10; j++){
  25.            for (i=9; i>0; i--){
  26.                if(vet[i-1] == 0 && vet[i]!= vet[i-1]){
  27.                            aux= vet[i];
  28.                            vet[i]=vet[i-1];
  29.                            vet[i-1]= aux;
  30.                }
  31.            }                  
  32.        }
  33.        
  34.        for(i = 0 ; i<10 ;i++){
  35.        printf("%d", vet[i]);
  36.        getch();
  37.        
  38.        }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement