Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- static int comp_double(const void *p1, const void *p2) {
- return *(double *) p1 < *(double *) p2;
- }
- int main(int ac, char **av) {
- printf("How many is random number generated? : ");
- int n = 0;
- scanf("%d", &n);
- double *randoms = (double *) malloc(n * sizeof(double));
- srand((unsigned int) time(NULL));
- for (int i = 0; i < n; i++)
- randoms[i] = (double) rand() / RAND_MAX;
- for (int i = 0; i < n; i++)
- printf("%g, ", randoms[i]);
- puts("");
- qsort(randoms, n, sizeof(double), comp_double);
- printf("1: %g\n2: %g\n", randoms[0], randoms[1]);
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement