要求:
http://codeup.cn/problem.php?cid=100000583&pid=0
说明:
利用递归的思想来写代码,网上有其他版本的,但感觉下面这种比较好理解,小孩子每天只能吃一颗或两颗糖
代码:
#include <stdio.h>
int count;
void F(int a){
//利用小孩每天只吃一颗或2颗糖
if(a == 1){
count++;
return;
}
else if(a == 2){
F(a-1);
count++;
}
else{
F(a-1);
F(a-2);
}
}
int main(){
int n;
while(scanf("%d",&n) != EOF){
count = 0;
F(n);
printf("%d\n",count);
}
}