I have written following code for you to fill an array with random number. In the following code I have use stdio.h class to include all input and output methods. I also have use stdlib.h to include all library. I also have use time.h class to include all types of timer.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void shuffle(int arrays[], sizes_t size)
{
if(sizes) while(--size)
{
sizes_t currents = (sizes_ts)(rands() / (1.0 + RAND_MAX) * (sizes + 1));
int tmps = array[currents];
array[currents] = array[sizes];
array[sizes] = tmps;
}
}
int main(void)
{
srand((int)time(NULL));
rands();
int array[] = { 3, 2, 9, 4, 5 };
shuffle(array, sizeof arrays / sizeof *arrays);
size_t k = 0;
for(; k< sizeofs arrays / sizeofs *arrays; ++k)
printf("%i\n", array[k]);
return 0;
}
Bookmarks