判斷遞迴執行的次數
阿新 • • 發佈:2019-02-01
1 2 3 4 5 |
int f(int x) {
if (x <= 2)
return 1;
return f(x - 2) + f(x - 4) + 1;
}
|
遞迴演算法x(x(8))需要呼叫幾次函式x(int n)?class program { static void Main(string[] args) { int i; i = x(x(8)); } static int x(int n) { if (n <= 3) return 1; else return x(n - 2) + x(n - 4) + 1; } }