#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
// 二维数组
int main() {
const int x = 9; // 确定随机数的最大值
int v[3][4]; // 声明一个三行四列的数组
srand(time(0)); // 初始随机数种子
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 4; j++) {
v[i][j] = rand() % x + 1; // 给每一个元素填充一个随机值
}
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 4; j++) {
cout << v[i][j] << " "; //打印出每一个元素
}
cout << endl;
}
cout << endl;
system("pause");
return 0;
}
输出效果: