C++接收从键盘输入的10个整数,存入一维数组,将前后元素依次对调打印输出

大哥们,打扰一下,C++接收从键盘输入的10个整数,存入一维数组,将前后元素依次对调打印输出
最新回答
献世佛

2025-06-19 02:37:45

#include<iostream>
using namespace std;
int main() {
int value[10];
for (int i = 1; i <= 10; i++) {
cout << "请输入第" << i << "个整数:" << endl;
cin >> value[i - 1];
}
cout << "反序输出:" << endl;
for (int i = 9; i >= 0; i--) {
cout << value[i] << ' ';
}
system("pause");
return 0;
}
拾柒

2025-06-19 09:03:53

#include<iostream>
using namespace std;
#include<stdio.h>
int main(){
int a[10],i,t;
cout << "input 10 int data" <<endl;
for (i=0;i<10;i++) cin >> a[i];
cout << "before: "; for (i=0;i<10;i++) cout << a[i] << " "; cout << endl;
for (i=0;i<5;i++){t=a[i];a[i]=a[9-i]; a[9-i]=t;};
cout << "after : "; for (i=0;i<10;i++) cout << a[i] << " "; cout << endl;

return 0;
}