解题思路:
注意事项:
参考代码:
#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语言程序设计教程(第三版)课后习题7.1 (C语言代码)浏览:755 |
A+B for Input-Output Practice (IV) (C++代码)浏览:710 |
【偶数求和】 (C语言代码)浏览:670 |
C语言程序设计教程(第三版)课后习题6.1 (C语言代码)浏览:574 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:642 |
1642题解浏览:778 |
A+B for Input-Output Practice (C语言代码)浏览:499 |
简单的a+b (C语言代码)浏览:570 |
多输入输出练习2 (C语言代码)浏览:1698 |
小O的数字 (C语言代码)浏览:1483 |