解题思路:
注意事项:
参考代码:
#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 人评分
Hello, world! (C语言代码)浏览:1194 |
C语言程序设计教程(第三版)课后习题6.11 (C语言代码)for循环浏览:1096 |
P1002 (C语言代码)浏览:965 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:411 |
母牛的故事 (C语言代码)浏览:915 |
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:534 |
C语言程序设计教程(第三版)课后习题11.8 (C语言代码)浏览:867 |
C二级辅导-求偶数和 (C语言代码)浏览:671 |
输出九九乘法表 (C语言代码)浏览:1047 |
C语言程序设计教程(第三版)课后习题8.6 (C语言代码)浏览:584 |