解题思路:
注意事项:
参考代码:
#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 人评分
2005年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:708 |
C二级辅导-阶乘数列 (C语言代码)浏览:614 |
矩形面积交 (Java代码)浏览:1213 |
分糖果 (C++代码)浏览:1438 |
C语言程序设计教程(第三版)课后习题11.3 (C语言代码)浏览:1020 |
A+B for Input-Output Practice (C语言代码)浏览:458 |
C语言程序设计教程(第三版)课后习题12.5 (C语言代码)浏览:762 |
字符删除 (C语言代码)浏览:714 |
【魔板】 (C++代码)浏览:1155 |
C语言程序设计教程(第三版)课后习题8.3 (C++代码)浏览:502 |