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); }