C/ C++,科園實中資科教甄109,B8
FB2:http://gg.gg/TedLeeMicrobitFB/
URL2:http://gg.gg/TedLeeMicrobit/
Line:ted2016.kpvs
Email:Lct4246@gmail.com
FB1:http://gg.gg/TedLeeFB/
Blog:http://gg.gg/TedLeeBlog/
URL1:http://gg.gg/TedLeeURL/
URL1:http://gg.gg/TedLeeURL/
May.7, 2020
問題解決(Problem Solving)之逻輯思維 =
心法: 程式設計哲思(Philosophical Thinking for Programming) +
技法:程式設計工法(Skills for Programming)
8. 下列程式碼執行後的輸出結果為 (8)
解析:
= fib(1) + fib(0) + fib(1)
= 1 + 1 + 1
= 3
#include <iostream>
#include <iomanip>
using namespace std;
int fib(int n) {
cout << n;
if (n < 2)
return 1;
else
return fib(n-1) + fib(n-2);
}
int main() {
int result = fib(3);
cout << result << endl;
return 0;
}
#include <iomanip>
using namespace std;
int fib(int n) {
cout << n;
if (n < 2)
return 1;
else
return fib(n-1) + fib(n-2);
}
int main() {
int result = fib(3);
cout << result << endl;
return 0;
}
沒有留言:
張貼留言