当前位置:网站首页>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[行][列]
边栏推荐
猜你喜欢
随机推荐
Shell executes SQL to send emails
灵魂发问:MySQL是如何解决幻读的?
HPC系统简介
Leetcode - 6135: the longest part of the figure
Pod environment variables and initContainer
2022.7.31-----leetcode.1161
leetcode-6135:图中的最长环
[Beyond programming] When the fig leaf is lifted, when people begin to accept everything
Holoview--Introduction
Optimal dazzle Oracle database support what kinds of type of the time and date
将Servlet项目改为SSM项目
解析MySQL数据库:“SQL优化”与“索引优化”
SkiaSharp's WPF self-painted five-ring bouncing ball (case version)
leetcode-6134: Find the closest node to the given two nodes
静态Pod、Pod创建流程、容器资源限制
量化日常工作指标
GBase 8c中怎么查询数据库配置参数,例如datestyle
基于MySql,Redis,Mq,ES的高可用方案解析
如何保证数据库与缓存数据一致性?
Pod环境变量和initContainer




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




