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

HTTP缓存小结
![[Cloud native] Grayscale release, blue-green release, rolling release, grayscale release explanation](/img/90/f7d85ac655d9206fefbd28e0fc81ba.png)
[Cloud native] Grayscale release, blue-green release, rolling release, grayscale release explanation

Classes and Objects (Part 2)

【重磅来袭】教你如何在RGBD三维重建中获取高质量模型纹理

本地事务与分布式事务

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

yarn安装详细教程说明、升级教程、修改yarn的全局和缓存目录、yarn基本命令

GeoServer + openlayers

The Prospects of the Metaverse and the Four Tracks

GeoServer
随机推荐
一文读懂Elephant Swap,为何为ePLATO带来如此高的溢价?
Excel使用Visual Basic Editor对宏进行修改
RISC-V调用惯例
让人上瘾的新一代开发神器,彻底告别Controller、Service、Dao等方法
科研中一些常用软件清单
几种常见的存储器
Redis cache penetration, breakdown, avalanche and consistency issues
(科普文)什么是碎片化NFT(Fractional NFT)
tiup install
【为宏正名】99%的人从第一天学习C语言就自废的武功
L2-007 家庭房产(vector、set、map的使用)
哨兵
TensorFlow自定义训练函数
Changing SELECT...FROM to FROM...SELECT doesn't 'fix' SQL
Applicable scenarios of TiDB tools
R中按照数字大小进行排序
Data Analysis Tools - DDL operations & DML operations in HQL
Compile, link, notes - 3
后浪来袭!阿里产出“第二代”容器技术手册及脑图,这也太香了吧
Local Transactions vs Distributed Transactions