include stdio include stdlib include time void outputArray int int len

 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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void outputArray(int *a, int len) {
int i;
for (i=0; i < len; i++)
printf("%i ", *(a+i) );
printf("\n");
}
void fillArray(int *a, int len) {
int i;
for (i=0; i < len; i++)
*(a + i) = i;
int x, y, var;
for ( i = 0; i < len; i++) {
x = rand() % len;
y = rand() % len;
var = *(a + y);
*(a + y) = *(a + x);
*(a+ x) = var;
}
}
//ritsuka nihuya ne ponyal
int main () {
srand(time(NULL));
// initializate dynamic random array
int *data, length = 10, i;
data = malloc( sizeof(int) * length );
fillArray(data, length);
outputArray(data, length);
// clear some data
free(data); data = 0;
return 0;
}