#include #include #include // Random Permutation // // Write a complete C program which takes an integer array and produces a // random permutation of the array. In other words, the program randomly // reshuffles the entries of the array (similar to shuffling a deck // of cards). The resulting array must be stored in the memory allocated // for the original array (i.e., the permutation is done in place). #define N 10 int main() { int a[N]= {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; int i; srand(time(NULL)); // We pick two random array indeces and we swap them. // We repeat 100 times to really make this random. // There are better ways to do the shuffling but this one is OK. for(i=0; i<100; i++) { int r1 = rand()%N; int r2 = rand()%N; // swap int temp= a[r1]; a[r1] = a[r2]; a[r2] = temp; } for(i=0; i