Baixe o app para aproveitar ainda mais
Prévia do material em texto
1 #include<stdio.h> 2 #include <stdlib.h> 3 #include<time.h> 4 #define N 10 5 6 int main (void) 7 { 8 srand(time(NULL)); 9 10 int i; 11 int LIM; 12 int auxiliar; 13 int vet[N]; 14 int inverte=1; 15 16 LIM=N-1; 17 18 printf("Vetor aleatorio gerado = [ "); 19 20 for(i=0; i<N; i++) 21 { 22 vet[i]= rand() % (20 - 11) + 10; 23 printf("%d ", vet[i]); 24 } 25 26 printf("]."); 27 28 do 29 { 30 inverte=0; 31 32 for(i=0; i<LIM; i++) 33 { 34 if(vet[i]<vet[i+1]) 35 { 36 inverte=1; 37 auxiliar=vet[i]; 38 vet[i]=vet[i+1]; 39 vet[i+1]=auxiliar; 40 } 41 } 42 LIM--; 43 } 44 while(inverte==1); 45 46 printf("\nOrdenacao decrescente: = [ "); 47 48 for(i=0; i<N; i++) 49 { 50 printf("%d ", vet[i]); 51 } 52 printf("]."); 53 }
Compartilhar