当前位置:网站首页>50.【Application of dynamic two-dimensional array】
50.【Application of dynamic two-dimensional array】
2022-08-01 09:28:00 【Lee is struggling...】

==================
[The number of columns can only be entered manually, the number of rows can be dynamic]
#include
using namespace std;
int main()
{
int m, n;
cout << "Please enter the number of lines:" << endl;
cin >> m;
cout << "Please enter the number of columns:" << endl;
cin >> n;
int(*p)[n]; // The number of columns cannot be entered dynamically
p = new int[m][n];
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 3; j++)
{
cout << "Please enter the value of p[" << i << "][" << j << "]" << endl;
cin >> p[i][j];
}
}
cout << "The output is:" << endl;
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 3; j++)
{
cout<< p[i][j]<<" ";
}
}
return 0;
}

[Manual input of the number of columns can be run]
#include
using namespace std;
int main()
{
int m, n;
cout << "Please enter the number of lines:" << endl;
cin >> m;
int(*p)[3];
p = new int[m][3];
for (int i = 0; i < m; i++)
{
for (int j = 0; j < 3; j++)
{
cout << "Please enter the value of p[" << i << "][" << j << "]" << endl;
cin >> p[i][j];
}
}
cout << "The output is:" << endl;
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 3; j++)
{
cout<< p[i][j]<<" ";
}
}
return 0;
}

【Basic format】
int (*p)[column]
p=new int[row][column]
边栏推荐
猜你喜欢
随机推荐
Static Pod, Pod Creation Process, Container Resource Limits
扁平数组转树结构实现方式
Do I need to introduce any dependencies to write data to clickhouse using flinksql?
HoloView--live data
SkiaSharp 之 WPF 自绘 五环弹动球(案例版)
笔记。。。。
微服务:事务管理
Classify GBase 8 s lock
Custom IP used in PCIE
MySQL query advanced - from the use of functions to table joins, do you remember?
TiDB的真实数据库数据是存在kv和还是pd上?
HoloView -- Tabular Datasets
SkiaSharp's WPF self-painted five-ring bouncing ball (case version)
指针的介绍及应用
How does UXDB return the number of records for all tables in the current database?
leetcode 42. 接雨水
net stop/start mysql80 拒绝访问
YOLOv7-Pose尝鲜,基于YOLOv7的关键点模型测评
ASP.NET Core 6框架揭秘实例演示[30]:利用路由开发REST API
The use of scrapy crawler framework




![ASP.NET Core 6框架揭秘实例演示[30]:利用路由开发REST API](/img/b3/0167c22f14b97eb0206696495af7b5.png)




