se hai già fatto i vettori allora puoi usare l'algoritmo bubble sort, è facile da capire e da implementare... ti porto qui un esempio che ho trovato su google, credo che funzioni:
codice:
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#define ARRAY_SIZE 20
void print_array(int *array) {
int x;
for(x = 0; x < ARRAY_SIZE; x++) {
if(x != ARRAY_SIZE-1)
fprintf(stdout, "%d, ", array[x]);
else
fprintf(stdout, "%d\n", array[x]);
}
}
int main() {
int iarray[ARRAY_SIZE];
int x, y, holder;
// Seed rand()
srand((unsigned int)time(NULL));
for(x = 0; x < ARRAY_SIZE; x++)
iarray[x] = (int)(rand() % 100);
fprintf(stdout, "Before Sort\n---------------\n");
print_array(iarray);
// Bubble sort method.
for(x = 0; x < ARRAY_SIZE; x++)
for(y = 0; y < ARRAY_SIZE-1; y++)
if(iarray[y] > iarray[y+1]) {
holder = iarray[y+1];
iarray[y+1] = iarray[y];
iarray[y] = holder;
}
fprintf(stdout, "\nAfter Sort\n---------------\n");
print_array(iarray);
}
se non hai fatto i vettori la vedo un pò difficile, forse dovresti fare dei confronti per verificare se un numero è più grande di un altro.
Spero di essere stato utile e di non aver detto sciocchezze