C++接收从键盘输入的10个整数,存入一维数组,将前后元素依次对调...
发布网友
发布时间:2024-10-07 10:17
我来回答
共2个回答
热心网友
时间:2024-10-07 11:45
#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;
}
热心网友
时间:2024-10-07 11: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;
}