csdn_spider/blog/ds19991999/原创-- C++实现随机产生一个二维数组.md

31 lines
723 B
Markdown
Raw Normal View History

2021-02-27 15:01:45 +00:00
# 原创
C++实现随机产生一个二维数组
# C++实现随机产生一个二维数组
```
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main() {
int n, m; //行数n和列数m
cin >> n >> m;
srand((unsigned)time(NULL));
for (int i = 0; i < n; i++)
{
for (int i = 0; i< m; i++)
{
cout << (rand() % 900) + 100 << " ";
//要取得[a,b)的随机整数,使用(rand() % (b-a))+ a;
//要取得[a,b]的随机整数,使用(rand() % (b-a+1))+ a;
//要取得(a,b]的随机整数,使用(rand() % (b-a))+ a + 1;
}
cout << endl;
}
return 0;
}
```