Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- double nrand(void) {
- int i;
- double r = 0;
- for (i = 0; i < 12; i++) r += rand() / ((double) RAND_MAX + 1.0);
- return r - 6;
- }
- int compare_double(const void *p1, const void *p2) {
- return *(double *) p1 - *(double *) p2;
- }
- int main(void) {
- int i;
- const int n = 100;
- double v[n];
- srand((unsigned) time(NULL));
- for (i = 0; i < n; i++) v[i] = nrand() * 280 + 750;
- for (i = 0; i < n; i++) printf("%.1lf ", v[i]); puts("");
- qsort(v, n, sizeof(double), compare_double);
- for (i = 0; i < n; i++) printf("%.1lf ", v[i]); puts("");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement