当前位置:网站首页>数组元素逆置
数组元素逆置
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;
}
边栏推荐
猜你喜欢

(Popular Science) What is Fractional NFT (Fractional NFT)

面试何惧调优!腾讯技术官私藏的性能优化方案手册,原理实战齐全

GeoServer

动态规划 --- 状态压缩DP 详细解释

Mysql database query is very slow. Besides the index, what else can be caused?

(科普文)什么是碎片化NFT(Fractional NFT)

Back waves are coming!Ali produced the "second generation" container technical manual and brain map, which is too fragrant

Placement Rules 使用文档

Mysql数据库查询好慢,除了索引,还能因为什么?

RISC-V calling conventions
随机推荐
Core Topics under Microservice Architecture (2): Design Principles and Core Topics of Microservice Architecture
【云原生】灰度发布、蓝绿发布、滚动发布、灰度发布解释
本地事务与分布式事务
GeoServer
Store Limit 使用文档
使用 TiUP 命令管理组件
R中按照数字大小进行排序
后浪来袭!阿里产出“第二代”容器技术手册及脑图,这也太香了吧
延时消息队列
ISELED---氛围灯方案的新选择
经典实例分割模型Mask RCNN原理与测试
[Cloud native] Alibaba Cloud ARMS business real-time monitoring
How to do a good job in technology selection
三维重建方法汇总
视频切换播放的例子(视频切换范例)代码
华为「天才少年」计划招募的博士们,迎来首秀!
Memory-mapped, bit-band operations
CS内网横向移动 模拟渗透实操 超详细
Excel使用Visual Basic Editor对宏进行修改
Sleuth+Zipkin(可视化) 服务链路追踪