当前位置:网站首页>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]
边栏推荐
- 解析MySQL数据库:“SQL优化”与“索引优化”
- SkiaSharp's WPF self-painted five-ring bouncing ball (case version)
- Delphi MDI appliction documents maximize display, remove buttons such as maximize and minimize
- 常见的API安全缺陷有哪些?
- Intensive reading of ACmix papers, and analysis of its model structure
- ogg同步oracle到mysql,字段里面可能有需要转义的字符,怎么配置转义?
- Lsky Pro 企业版手动升级、优化教程
- various network protocols
- rpm and yum
- ACmix 论文精读,并解析其模型结构
猜你喜欢
随机推荐
网络个各种协议
Go-Excelize API源码阅读(八)——GroupSheets(sheets []string)、UngroupSheets()
scrapy爬虫框架的使用
将aof文件转换为命令waoffle安装和使用
SkiaSharp 之 WPF 自绘 五环弹动球(案例版)
Microsoft Azure & NVIDIA IoT 开发者季 I|Azure IoT & NVIDIA Jetson 开发基础
获取页面数据的方法
How to ensure the consistency of database and cache data?
How programmers learn open source projects, this article tells you
杨辉三角(c语言实现)
Quantify daily work metrics
USB Protocol (2) Terminology
2022.7.31-----leetcode.1161
SAP ABAP ALV+SMARTFORS 表分页 报表打印程序
如何保证数据库与缓存数据一致性?
Redis中间件(从搭建到弃坑)
报告:想学AI的学生数量已涨200%,老师都不够用了
UXDB如何返回当前数据库所有表的记录数?
【STM32】入门(二):跑马灯-GPIO端口输出控制
STM32个人笔记-嵌入式C语言优化







