解题思路:
注意事项:
参考代码:
#include <stdio.h>
int cowNum(int n);
int main()
{
int n;
while(scanf("%d", &n) && n)
printf("%d\n", cowNum(n));
return 0;
}
int cowNum(int n)
{
if(n <= 4)
return n;
int childCow1 = 1, childCow2 = 1, childCow3 = 1, momCow = 1;
for(int i = 5; i <= n; i++)
{
momCow += childCow3;
childCow3 = childCow2;
childCow2 = childCow1;
childCow1 = momCow;
}
return childCow1 + childCow2 + childCow3 + momCow;
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题11.5 (C语言代码)浏览:967 |
【亲和数】 (C语言代码)浏览:536 |
【绝对值排序】 (C语言代码)浏览:713 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)浏览:937 |
完数 (C语言代码)浏览:685 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:560 |
C语言程序设计教程(第三版)课后习题10.1 (C语言代码)浏览:560 |
1050题解(结构体数组与结构体指针的使用)浏览:1105 |
C语言程序设计教程(第三版)课后习题7.4 (C语言代码)浏览:484 |
C语言程序设计教程(第三版)课后习题8.7 (C语言代码)浏览:526 |