思路:把输入的数字存到一个数组里,这里我用的是方法是先赋值给一个变量,在把变量的值给数组,(当然也可以直接给数组赋值)并且记录个数,然后反向for循环输出即可
#include<iostream>
using namespace std;
int main() {
int a[101];
int temp = 1, count = 0;
while (1) {
cin >> temp;
if (temp == 0) {
break;
}
a[count] = temp;
count++;
}
for (int i = count-1; i >= 0; i--) {
cout << a[i] << " ";
}
}