当前位置:网站首页>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]
边栏推荐
- Manual upgrade and optimization tutorial of Lsky Pro Enterprise Edition
- Microsoft Azure & NVIDIA IoT developers season I | Azure IoT & NVIDIA Jetson development foundation
- 将Servlet项目改为SSM项目
- Optimal dazzle Oracle database support what kinds of type of the time and date
- PHP获取时间戳后写数据库的一个问题
- GBase 8c中怎么查询数据库配置参数,例如datestyle
- sql server, FULL模式, dbcc shrinkfile(2,1) 不能收缩事务日志,还是原来的大小,是为什么?
- 报告:想学AI的学生数量已涨200%,老师都不够用了
- Shell:条件测试操作
- leetcode-6132: Make all elements in array equal to zero
猜你喜欢
Change Servlet project to SSM project
Shell: Conditional test action
leetcode-6132:使数组中所有元素都等于零
Leicester Weekly 304 6135. The longest ring in the picture Inward base ring tree
走进音视频的世界——mp3封装格式
将Servlet项目改为SSM项目
various network protocols
程序员如何学习开源项目,这篇文章告诉你
[Beyond programming] When the fig leaf is lifted, when people begin to accept everything
如何保证数据库与缓存数据一致性?
随机推荐
Idea common plugins
Prime Ring Problem
PHP获取时间戳后写数据库的一个问题
HoloView——实时数据
高级驾驶辅助系统ADAS简介
Ogg synchronizes oracle to mysql, there may be characters that need to be escaped in the field, how to configure escape?
JVM内存模型之深究模型特征
Mysql database deployment and initialization steps
【Untitled】
Leicester Weekly 304 6135. The longest ring in the picture Inward base ring tree
leetcode-6135:图中的最长环
sql server, FULL mode, dbcc shrinkfile(2,1) can not shrink the transaction log, or the original size, why?
消息队列面试题(2022最新整理)
leetcode 42. Catch the rain
SAP ABAP ALV+SMARTFORS 表分页 报表打印程序
Shell: Conditional test action
Pod environment variables and initContainer
实验。。。。
Redis中间件(从搭建到弃坑)
Pytest | skip module interface test automation framework