二维数组的行遍历和列遍历
c++语言描述
#include <iostream>
using namespace std;
int arr[4][6] = { 0 };
int row = sizeof(arr) / sizeof(arr[0]);//行
int col = sizeof(arr[0]) / sizeof(int);//列
//打印arr数组
void printArr() {
for (int i = 0;i < row;i++) {
for (int j = 0;j < col;j++) {
cout << arr[i][j] << "\t";
}
cout << endl;
}
cout << endl;
}
void main() {
//行遍历
for (int i = 0;i < row;i++) {
for (int j = 0;j < col;j++) {
arr[i][j] = i*(col)+j+1;
}
}
printArr();
//列遍历
for (int j = 0;j < col;j++) {
for (int i = 0;i < row;i++) {
arr[i][j] = j*(row)+i+1;
}
}
printArr();
system("pause");
}
评论区
请写下您的评论...
猜你喜欢
ofc
c#二维数组的初始化和遍历
weblog
3158
定义数组int[,]area={{0,0},{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,-1},{-1,1}};遍历数组for(inti=0
weblog
3927
vue使用v-for遍历数组和遍历对象splic(...)方法的使用请参考:http://www.jiajiajia.club/blog/artical/262!DOCTYPEhtmlhtml
blog
二叉树的遍历-(递归法)和(非递归法)
数据结构与算法
5054
整理二叉树的遍历-(递归法)和(非递归法)-笔记先序遍历、中序遍历、后续遍历、层级遍历。1.节点信息:packagetree;publicclassNodeE{ privateEe;//数据域
blog
mybatis遍历int数组
框架
1024
mybatis遍历int数组foreachcollection="ids"index="index"item="item" open="("separator=","close=")" #{item}/foreach
ofc
N叉树的前序遍历
official
832
leetcode第589题题目描述给定一个N叉树,返回其节点值的前序遍历。例如,给定一个3叉树:返回其前序遍历:[1,3,5,6,2,4]。解题思路递归遍历,深度优先搜索代码(java
数据结构与算法
8153
)java代码实现importjava.util.LinkedList;/***二叉树结点类*@author硅谷探秘者(jia)*/classNode{ publicintdata; publicNodele
blog
for in 和 for of 的区别
javascript,前端
780
jsjavascriptforin和forof的区别,forof遍历的原理
一、区别
forin是ES5的语法,forof是ES6的语法forin是无序遍历数组或对象的,也就是随机遍历,不按照顺序来
算法基础
1206
Java中遍历集合的方式以list集合为例,有三种遍历方式。ListStringlist=newArrayList();
list.add("2");
list.add("2");
list.add
最新发表
归档
2018-11
12
2018-12
33
2019-01
28
2019-02
28
2019-03
32
2019-04
27
2019-05
33
2019-06
6
2019-07
12
2019-08
12
2019-09
21
2019-10
8
2019-11
15
2019-12
25
2020-01
9
2020-02
5
2020-03
16
2020-04
4
2020-06
1
2020-07
7
2020-08
13
2020-09
9
2020-10
5
2020-12
3
2021-01
1
2021-02
5
2021-03
7
2021-04
4
2021-05
4
2021-06
1
2021-07
7
2021-08
2
2021-09
8
2021-10
9
2021-11
16
2021-12
14
2022-01
7
2022-05
1
2022-08
3
2022-09
2
2022-10
2
2022-12
5
2023-01
3
2023-02
1
2023-03
4
2023-04
2
2023-06
3
2023-07
4
2023-08
1
2023-10
1
2024-02
1
2024-03
1
2024-04
1
标签
算法基础
linux
前端
c++
数据结构
框架
数据库
计算机基础
储备知识
java基础
ASM
其他
深入理解java虚拟机
nginx
git
消息中间件
搜索
maven
redis
docker
dubbo
vue
导入导出
软件使用
idea插件
协议
无聊的知识
jenkins
springboot
mqtt协议
keepalived
minio
mysql
ensp
网络基础
xxl-job
rabbitmq
haproxy
srs
音视频
webrtc
javascript
目录
没有一个冬天不可逾越,没有一个春天不会来临。最慢的步伐不是跬步,而是徘徊,最快的脚步不是冲刺,而是坚持。