当前位置:网站首页>数组元素逆置
数组元素逆置
2022-07-30 15:14:00 【51CTO】
using namespace std;
int main1() {
int arr[5] = { 2,3,4,5,6 };
cout << "数组逆置前:" << endl;
for (int i = 0; i < 5; i++) {
cout << arr[i] << endl;
}
int start = 0;//记录起始下标的位置
int end = sizeof(arr) / sizeof(arr[0])-1;//记录结束下标的位置
//实现元素互换
while (start < end) {
int temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
//下标更新
start++;
end--;
}
//打印逆置后的数组
cout << "数组元素逆置后" << endl;
for (int i = 0; i < 5; i++) {
cout<< arr[i] << endl;
}
system("pause");
return 0;
}
边栏推荐
- Mysql database query is very slow. Besides the index, what else can be caused?
- timed task corn
- 代码随想录笔记_哈希_1l两数之和
- Core Topics under Microservice Architecture (2): Design Principles and Core Topics of Microservice Architecture
- golang modules初始化项目
- 服务器装好系统的电脑怎么分区
- Redis cache penetration, breakdown, avalanche and consistency issues
- 软件包 - 笔记
- 动态规划 --- 状态压缩DP 详细解释
- 视频加密的误解
猜你喜欢
Mysql database query is very slow. Besides the index, what else can be caused?
在树莓派上驱动CSI摄像头
解析字符串拼接的两种情况
Shell脚本的概念
yarn安装详细教程说明、升级教程、修改yarn的全局和缓存目录、yarn基本命令
481-82 (105, 24, 82, 34, 153),
[Cloud native] Alibaba Cloud ARMS business real-time monitoring
Excel uses Visual Basic Editor to modify macros
经典实例分割模型Mask RCNN原理与测试
Flask之路由(app.route)详解
随机推荐
SEATA分布式事务
数据库-SQL
tiup install
Alluxio为Presto赋能跨云的自助服务能力
Core Topics under Microservice Architecture (2): Design Principles and Core Topics of Microservice Architecture
(Crypto必备干货)详细分析目前NFT的几大交易市场
Placement Rules 使用文档
R中按照数字大小进行排序
三维重建方法汇总
tiup env
Manage components using TiUP commands
Shell脚本的概念
存储器映射、位带操作
Sleuth+Zipkin (visualization) service link tracking
Introduction to golang image processing library image
Changing SELECT...FROM to FROM...SELECT doesn't 'fix' SQL
延时消息队列
Flask之路由(app.route)详解
B+树索引页大小是如何确定的?
二、判断 & 循环