C语言如何把rand()产生的随机数存入二维数组
#include
#include
#include
int main(void){
srand((unsigned)time(NULL));
int i,j,a[5][5],b;
for(b = 0; b < 25; ++b){
printf("%d ",10+rand()%91);
}
a[5][5]=10+rand()%91;
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main(void){
srand((unsigned)time(NULL));
int i,j,a[5][5];
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
a[i][j] = 10+rand()%91;
printf("%4d",a[i][j]);
}
printf("\n");
}
}
遍历数组赋值
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
a[i][j]=10+rand()%91;
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main(void){
srand((unsigned)time(NULL));
int i,j,a[5][5],b,c;
for(b = 0; b < 5; b++){
for(c = 0; c < 5; c++){
a[b][c] = rand()%91;
}
}