标签:pre pac bsp std stream style end ret ace
请教神犇:
1 #include<iostream> 2 using namespace std; 3 4 int fab(int n) 5 { 6 if (n == 1 || n == 2) 7 { 8 return 1; 9 } else { 10 return fab(n - 2) + fab(n - 1); 11 } 12 13 } 14 15 int fab2 (int n) 16 { 17 int a[20]; 18 a[1] = 1; 19 a[2] = 1; 20 for (int i = 3; i <= n; i++) 21 { 22 a[i] = a[i-2] + a[i-1]; 23 } 24 return a[n]; 25 } 26 27 int main() 28 { 29 for (int i = 1; i < 20; i++) 30 { 31 cout << fab (i) << endl; 32 } 33 cout << endl; 34 for (int i = 1; i < 20; i++) 35 { 36 cout << fab2 (i) << endl; 37 } 38 return 0; 39 } 40
标签:pre pac bsp std stream style end ret ace
原文地址:https://www.cnblogs.com/juxq/p/9737242.html