当前位置:网站首页>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[行][列]
边栏推荐
- Redis 3.2.3 crashed by signal: 11 服务宕机问题排查
- 获取页面数据的方法
- MySQL query advanced - from the use of functions to table joins, do you remember?
- How to get page data
- Redis中间件(从搭建到弃坑)
- pytest interface automation testing framework | skip test classes
- pytest interface automation testing framework | parametrize source code analysis
- SkiaSharp 之 WPF 自绘 五环弹动球(案例版)
- 企业数据虚拟化综合指南
- GBase 8c中怎么查询数据库配置参数,例如datestyle
猜你喜欢

HoloView -- Tabular Datasets

VoLTE Basic Learning Series | Enterprise Voice Network Brief

leetcode-6135:图中的最长环

Prime Ring Problem

Microsoft Azure & NVIDIA IoT 开发者季 I|Azure IoT & NVIDIA Jetson 开发基础

sqlserver怎么查询一张表中同人员的交叉日期

报告:想学AI的学生数量已涨200%,老师都不够用了

various network protocols

Leetcode - 6135: the longest part of the figure

STM32个人笔记-看门狗
随机推荐
Redis中间件(从搭建到弃坑)
安装GBase 8c数据库的时候,报错显示“Resource,如何解决?
leetcode-6135:图中的最长环
力扣周赛304 6135. 图中的最长环 内向基环树
获取页面数据的方法
Introduction to ADAS
STM32个人笔记-看门狗
【Unity3D】相机
C语言中编译时出现警告C4013(C语言不加函数原型产生的潜在错误)
ACmix 论文精读,并解析其模型结构
常见的API安全缺陷有哪些?
走进音视频的世界——mp3封装格式
Go-Excelize API源码阅读(八)——GroupSheets(sheets []string)、UngroupSheets()
navicat mysql 内存占用过高,被强制关闭
Static Pod, Pod Creation Process, Container Resource Limits
HoloView -- Tabular Datasets
leetcode-6134:找到离给定两个节点最近的节点
[Interview: Concurrency 39: Multithreading: Thread Pool] ThreadPoolExecutor Class - Submit, Stop
如何保证数据库与缓存数据一致性?
报告:想学AI的学生数量已涨200%,老师都不够用了