当前位置:网站首页>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[行][列]
边栏推荐
- 《时代》杂志:元宇宙时代将改变世界
- sqlserver怎么查询一张表中同人员的交叉日期
- 最新的Cesium和Three的整合方法(附完整代码)
- 笔记。。。。
- Naive Bayes--Study Notes--Basic Principles and Code Implementation
- 【编程之外】当遮羞布被掀开,当人们开始接受一切
- Manual upgrade and optimization tutorial of Lsky Pro Enterprise Edition
- leetcode-6135:图中的最长环
- ASP.NET Core 6框架揭秘实例演示[30]:利用路由开发REST API
- leetcode-6133:分组的最大数量
猜你喜欢
随机推荐
自定义IP在PCIE中使用
leetcode-6132: Make all elements in array equal to zero
js中如何实现深拷贝?
【应用推荐】常见资源管理器整理,含个人使用体验和产品选型推荐
Explain / Desc 执行计划分析
HoloView -- Tabular Datasets
Install GBase 8 c database, the error shows "Resource, how to solve?
SkiaSharp's WPF self-painted five-ring bouncing ball (case version)
热修复技术可谓是百花齐放
Ogg synchronizes oracle to mysql, there may be characters that need to be escaped in the field, how to configure escape?
network basic learning
In the background of the GBase 8c database, what command is used to perform the master-slave switchover operation for the gtm and dn nodes
在GBase 8c数据库后台,使用什么样的命令来对gtm、dn节点进行主备切换的操作
【无标题】
Redis middleware (from building to refuse pit)
PerViT: 神经网络也能像人类利用外围视觉一样观察图像!
程序员如何学习开源项目,这篇文章告诉你
Shell executes SQL to send emails
JVM 运行时数据区与JMM 内存模型详解
HoloView -- Tabular Datasets