-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpgave9-5.c
54 lines (40 loc) · 925 Bytes
/
Opgave9-5.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int int_compare(const void *ip1, const void *ip2){
int result;
int *ipi1 = (int *)ip1,
*ipi2 = (int *)ip2;
if (*ipi1 < *ipi2)
result = -1;
else if (*ipi1 > *ipi2)
result = 1;
else
result = 0;
return result;
}
int main(){
srand(time(0));
double* ptr;
double n = 100;
int i;
ptr = (double*)malloc(n * sizeof(double));
if (ptr == NULL) {
printf("Pladser ikke fundet\n");
exit(0);
}
else {
for (i = 0; i < n; ++i) {
ptr[i] = i + 1;
}
printf("Dine 100 usorterede tal er: \n");
for (i = 0; i < n; ++i) {
printf("%d, ", ptr[i] = rand() % 500+1);
}
}
qsort(ptr, 100, sizeof(double), int_compare);
for (i = 0; i < n; ++i) {
printf("%d ", ptr[i]);
}
return 0;
}