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

31 lines
723 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# 原创
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;
}
```