当前位置:网站首页>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[行][列]
边栏推荐
- STM32个人笔记-嵌入式C语言优化
- Leicester Weekly 304 6135. The longest ring in the picture Inward base ring tree
- leetcode-6134:找到离给定两个节点最近的节点
- 372. 超级次方
- 【Untitled】
- 18张图,直观理解神经网络、流形和拓扑
- Parsing MySQL Databases: "SQL Optimization" vs. "Index Optimization"
- Pytest | skip module interface test automation framework
- Classify GBase 8 s lock
- HoloView -- Tabular Datasets
猜你喜欢
如何保证数据库与缓存数据一致性?
HoloView -- Tabular Datasets
Leetcode - 6135: the longest part of the figure
opencv创建窗口—cv.namedWindow()
22 Grab the Seat 1 C.Grab the Seat (Geometry + Violence)
Analysis of High Availability Solution Based on MySql, Redis, Mq, ES
Get the Token from the revised version of Qubutu Bed
【编程之外】当遮羞布被掀开,当人们开始接受一切
leetcode-6132: Make all elements in array equal to zero
leetcode-6134: Find the closest node to the given two nodes
随机推荐
BGP综合实验
XX市消防救援指挥中心实战指挥平台多链路聚合解决方案实例
GBase 8c中怎么查询数据库配置参数,例如datestyle
Ogg synchronizes oracle to mysql, there may be characters that need to be escaped in the field, how to configure escape?
STM32个人笔记-嵌入式C语言优化
Idea 常用插件
TiDB的真实数据库数据是存在kv和还是pd上?
报告:想学AI的学生数量已涨200%,老师都不够用了
Intensive reading of ACmix papers, and analysis of its model structure
Redis learning
GBase 8s 锁分类
杨辉三角(c语言实现)
【Untitled】
Redis中间件(从搭建到弃坑)
Microsoft Azure & NVIDIA IoT 开发者季 I|Azure IoT & NVIDIA Jetson 开发基础
zip package all files in the directory (including hidden files/folders)
HoloView--Customization
codeforces每日5题(均1600)-第二十七天
SkiaSharp's WPF self-painted five-ring bouncing ball (case version)
net stop/start mysql80 access denied