C++实现随机产生一个二维数组

#include    
#include    
#include   
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;
}

你可能感兴趣的:(C++)