这题的递归方式给的好清楚
2024-12-04 18:39:02
发布于:北京
29阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
int f(int x){
if (x == 1){
cout << "1";
return 0;
}
printf("%d->", x);
if (x % 2 == 0){
return f(x / 2);
} else {
return f(3 * x + 1);
}
}
int main(){
int n;
cin >> n;
f(n);
}
这里空空如也
有帮助,赞一个