Problem D: 程序填充(递归函数):数列2项和
Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 2601 Solved: 2117
Description
下面程序中"____ N ____"是根据程序功能需要填充部分,请完成程序填充(注意:不得加行、减行、加句、减句,否则后果自负)。 该程序功能:数列的第1、2项均为1,此后各项值均为该项前二项之和。计算数列第30项的值。 #include long f(int n); void main() { printf("%ld\n",_____1____); } long f(int n) { if(_______2______) return 1; else return ______3_____; }
Input
无
Output
数列第30项的值。
Sample Input
无
Sample Output
832040
#include<stdio.h> long f(int n); void main() { printf("%ld\n",f(30)); } long f(int n) { if(n==1||n==2) return 1; else return f(n-1)+f(n-2); }