当前位置:网站首页>Array element inverse
Array element inverse
2022-07-30 15:53:00 【51CTO】
using namespace std;
int main1() {
int arr[5] = { 2,3,4,5,6 };
cout << "before array inversion:" << endl;
for (int i = 0; i < 5; i++) {
cout << arr[i] << endl;
}
int start = 0;//Record the position of the starting subscript
int end = sizeof(arr) / sizeof(arr[0])-1;//The position of the end subscript of the record
//Realize element exchange
while (start < end) {
int temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
//Subscript update
start++;
end--;
}
//Print the reversed array
cout << "Array elements are inverted" << endl;
for (int i = 0; i < 5; i++) {
cout<< arr[i] << endl;
}
system("pause");
return 0;
}
边栏推荐
- php字符串如何去除第一个字符
- 哨兵
- Configuration - Notes
- When the vite multi-page application refreshes the page, it will not be in the current route and will return to the root route
- 数组元素逆置
- php如何截取字符串的前几位
- [AGC] Quality Service 1 - Example of Crash Service
- Core Topics under Microservice Architecture (2): Design Principles and Core Topics of Microservice Architecture
- 481-82(105、24、82、34、153)
- Promise Notes (1)
猜你喜欢
随机推荐
100w的数据表比1000w的数据表查询更快吗?
【嵌入式】适用于Cortex-M3(STM32F10x)的IQmath库
(Popular Science) What is Fractional NFT (Fractional NFT)
PMP每日一练 | 考试不迷路-7.30(包含敏捷+多选)
TiUP FAQ
华为ADS获取转化跟踪参数报错:getInstallReferrer IOException: getInstallReferrer not found installreferrer
php如何查询字符串出现位置
三维重建方法汇总
tiup install
nodejs环境变量设置
动态规划 --- 状态压缩DP 详细解释
TiUP 术语及核心概念
Configuration - Notes
[Developers must see] [push kit] Collection of typical problems of push service 2
武汉星起航:海外仓基础建设成为跨境电商企业的一大出海利器
AI遮天传 DL-CNN
timed task corn
Manage components using TiUP commands
How to split microservices?
L2-007 家庭房产(vector、set、map的使用)