当前位置:网站首页>50.【动态二维数组的运用】
50.【动态二维数组的运用】
2022-08-01 09:25:00 【李在奋斗……】
==============
【列数只能手动输入,行数可以动态】
#include <iostream>
using namespace std;
int main()
{
int m, n;
cout << "请输入行数为:" << endl;
cin >> m;
cout << "请输入列数为:" << endl;
cin >> n;
int(*p)[n]; // 列数不能动态输入
p = new int[m][n];
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 3; j++)
{
cout << "请输入p[" << i << "][" << j << "]的值" << endl;
cin >> p[i][j];
}
}
cout << "输出为:" << endl;
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 3; j++)
{
cout<< p[i][j]<<" ";
}
}
return 0;
}
【手动输入列数可以运行】
#include <iostream>
using namespace std;
int main()
{
int m, n;
cout << "请输入行数为:" << 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 << "请输入p[" << i << "][" << j << "]的值" << endl;
cin >> p[i][j];
}
}
cout << "输出为:" << endl;
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 3; j++)
{
cout<< p[i][j]<<" ";
}
}
return 0;
}
【基本格式】
int (*p)[列]
p=new int[行][列]
边栏推荐
- 【杭电多校第四场 B题】最短路图+缩点dp
- [Tear AHB-APB Bridge by hand]~ Why aren't the lower two bits of the AHB address bus used to represent the address?
- A problem with writing to the database after PHP gets the timestamp
- SkiaSharp's WPF self-painted five-ring bouncing ball (case version)
- Manual upgrade and optimization tutorial of Lsky Pro Enterprise Edition
- Detailed explanation of JVM runtime data area and JMM memory model
- Naive Bayes--Study Notes--Basic Principles and Code Implementation
- 179. 最大数
- What do the values 1, 2, and 3 in nodetype mean?
- How to ensure the consistency of database and cache data?
猜你喜欢
随机推荐
Graduation thesis writing skills
Shell:条件测试操作
HoloView -- Tabular Datasets
Redis学习
HoloView -- Tabular Datasets
SkiaSharp's WPF self-painted five-ring bouncing ball (case version)
STM32个人笔记-看门狗
pytest interface automation testing framework | pass in parameter values in the form of function return values
HoloView -- Tabular Datasets
AC与瘦AP的WLAN组网实验
various network protocols
sql server, FULL模式, dbcc shrinkfile(2,1) 不能收缩事务日志,还是原来的大小,是为什么?
Idea common plugins
sql server, FULL mode, dbcc shrinkfile(2,1) can not shrink the transaction log, or the original size, why?
解析MySQL数据库:“SQL优化”与“索引优化”
笔记。。。。
STM32个人笔记-嵌入式C语言优化
Static Pod, Pod Creation Process, Container Resource Limits
YOLOv7-Pose尝鲜,基于YOLOv7的关键点模型测评
最新的Cesium和Three的整合方法(附完整代码)