Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int compare(const void *p1, const void *p2) {
- return *(int *) p2 - *(int *) p1;
- }
- int main(int ac, char **av) {
- const int DATA_NO = 100;
- int data[DATA_NO];
- int i;
- srand((unsigned int) time(NULL));
- data[0] = rand() % 10;
- for (i = 1; i < DATA_NO; i++) {
- data[i] = data[i - 1] + rand() % 10;
- if (data[i] == data[i - 1]) data[i]++;
- }
- for (i = 0; i < DATA_NO; i++) {
- if (i % 10 == 0) printf("\n");
- printf("%4d", data[i]);
- }
- printf("\n");
- qsort(data, DATA_NO, sizeof(int), compare);
- for (i = 0; i < DATA_NO; i++) {
- if (i % 10 == 0) printf("\n");
- printf("%4d", data[i]);
- }
- printf("\n");
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement