本题思路:
1.要注意 i-1
#include<iostream>
using namespace std;
int main() {
int n, a[110];
int i = 1;
cin >> n;
a[0] = n;
while (n != 1) {
if (n % 2 == 0) {
n = n / 2;
a[i] = n;
i++;
}
else {
n = n * 3 + 1;
a[i] = n;
i++;
}
}
for (int j = i - 1; j >= 0; j--) {
if (j != 0)
cout << a[j] << ' ';
else
cout << a[j];
}
}