Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<ctype.h>
- #include<string.h>
- #define SIZE 10000
- int cmp(const void *a, const void *b)
- {
- const double *ad, *bd;
- ad = (const double*)a;
- bd = (const double*)b;
- if (*ad < *bd)
- {
- return -1;
- }
- else if (*ad > *bd)
- {
- return 1;
- }
- else
- {
- return 0;
- }
- }
- int main()
- {
- char *nums = (char*) malloc (SIZE * sizeof(char));
- fgets(nums, SIZE, stdin);
- nums[(strlen(nums)) - 1] = '\0';
- double *numses = (double *) malloc (sizeof(double));
- char *pch;
- size_t i = 1;
- pch = strtok(nums, " ");
- while (pch != NULL){
- numses[i-1] = atof(pch);
- pch = strtok(NULL, " ");
- ++i;
- numses = realloc(numses, i * sizeof(double));
- }
- // for (int j = 0; j < i - 1; j++) printf("%f ", numses[j]);
- puts("!!");
- qsort(numses, i-1, sizeof(double), cmp);
- for (int j = 0; j < i - 1; j++) printf("%g ", numses[j]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement