2
Do you have another method to sort vector/matrix in ascending or descending order other than the one I used ? ( What would you change in this code to make it " better " ? )
#include <stdio.h>
#include <stdlib.h>
void ordem (int vetor[], int tamanho);
int main ( void ) {
int tamanho, *vetor;
printf("\nInforme o tamanho do vetor: ");
scanf("%i",&tamanho);
vetor = (int *) malloc(tamanho * sizeof(int));
for ( int i = 0; i < tamanho; i++){
printf("\nInforme o valor %i: ", i + 1);
scanf("%i",&vetor[i]);
}
ordem (vetor, tamanho);
puts("\n-----------------------------");
for ( int p = 0; p < tamanho; p++){
printf("\n%i ",vetor[p]);
} puts("");
free(vetor);
return 0;
}
void ordem (int vetor[], int tamanho){
int cache = 0;
for ( int i = 0; i < tamanho; i++){
for ( int h = i + 1; h < tamanho; h++){
if (vetor[i] > vetor[h]){
cache = vetor[i];
vetor[i] = vetor[h];
vetor[h] = cache;
}
}
}
}
The problem is precisely that there are numerous. TAKE A LOOK AT [Ask].
– Maniero