#include<iostream>
using namespace std;
int main()
{
const int m = 5, n = 5;
int a[m][n];
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
a[i][j] = i * n + j + 1;
}
}
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
cout << a[i][j];
if (j == n - 1)
{
cout << endl;
}
else
{
cout << "\t";
}
}
}
return 0;
}
#include<iostream>
using namespace std;
int main()
{
//定义 m 行 n 列的二维数组
int m, n;
cin >> m >> n;
int** a = new int* [m];
for (int i = 0; i < m; i++)
{
a[i] = new int[n];//一维数组定义:int *a = new int[n];
}
//为数组各元素赋值
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
if (i == 0 || j == 0)
{
a[i][j] = 1;
}
else
{
a[i][j] = a[i - 1][j] + a[i][j - 1];
}
}
}
//输出
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
cout << a[i][j];
if (j == n - 1)
{
cout << endl;
}
else
{
cout << " ";
}
}
}
//回收空间!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
for (int i = 0; i < m; i++)
{
delete[]a[i];//delete 先释放j再释放i
}
delete[]a;
return 0;
}