#28297: CPP


11030067@mail.hpsh.tp.edu.tw (和平110級鄧雨珊)

學校 : 臺北市立和平高級中學
編號 : 163096
來源 : [61.64.210.174]
最後登入時間 :
2022-10-23 16:54:59
e357. 遞迴函數練習 | From: [203.72.60.241] | 發表日期 : 2021-11-26 14:41

#include <iostream>
using namespace std;

int f(int x){
if (x==1){
return 1;
}
if (x%2==0){
return f(x/2);
}
else {
return x=f(x-1)+f(x+1);
}
}
int main(){
int n;
while (cin >> n){
cout << f(n) <<endl;
}
}
 
ZeroJudge Forum