#include #include #include long int random(); void srandom(unsigned int); int arr[100]; int narr; int cmp(const void *x, const void *y) { int *px, *py; px = (int *) x; py = (int *) y; return(*px - *py); } int main(void) { int i; /* initialize the PRNG */ (void) srandom(time(NULL)); /* need at least 9 but no more than 100 numbers */ narr = random() % 90 + 11; /* generate the numbers */ for(i = 0; i < narr; i++) arr[i] = random() % 100; /* print them out */ printf("UNSORTED:\n"); for(i = 0; i < narr; i++) printf("%d ", arr[i]); putchar('\n'); /* sort them */ qsort(arr, narr, sizeof(int), (int (*)(const void *, const void *) ) cmp); /* print them out */ printf("SORTED:\n"); for(i = 0; i < narr; i++) printf("%d ", arr[i]); putchar('\n'); /* bye! */ return(0); }