C语言如何实现把一个二维数组随机打乱再输出?
这是我目前的得到的二维数组。#include<stdio.h>
#include<stdlib.h>
#include<time.h>
main()
{
int a[20];
int a1[4][4];
int a2[4][4];
int a3[4][4];
int i, j,k,z;
int m, n;
srand((int)time(0));
a[0] = rand() % 20 + 1;
for (i = 1; i<20; i++)
{
a[i] = rand() % 20 + 1;
for (j = 0; j<i; j++)
{
if (a[i] == a[j])
{
i--;
}
}
}
for (m = 0,i=0; m < 4;m++,i=i+4)
{
a1[m][0] = a[i];
a1[m][1] = a[i+1];
a1[m][2] = a[i+2];
a1[m][3] = a[i+ 3];
}
for (m = 2,i=0; m < 4;m++,i=i+4)
{
a1[m][0] = a[i];
a1[m][1] = a[i + 1];
a1[m][2] = a[i + 2];
a1[m][3] = a[i + 3];
}
printf("%d %d %d %d\n\n", a1[0][0], a1[0][1], a1[0][2], a1[0][3]);
printf("%d %d %d %d\n\n", a1[1][0], a1[1][1], a1[1][2], a1[1][3]);
printf("%d %d %d %d\n\n", a1[2][0], a1[2][1], a1[2][2], a1[2][3]);
printf("%d %d %d %d\n\n", a1[3][0], a1[3][1], a1[3][2], a1[3][3]);
}