解题思路:
注意事项:
参考代码:
#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 人评分
点我有惊喜!你懂得!浏览:1390 |
A+B for Input-Output Practice (IV) (C语言代码)浏览:508 |
C语言程序设计教程(第三版)课后习题6.7 (C语言代码)浏览:625 |
C语言训练-大、小写问题 (C语言代码)浏览:2347 |
淘淘的名单 (C语言代码)答案错误???浏览:590 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:772 |
杨辉三角 (C语言代码)浏览:483 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:572 |
图形输出 (C语言代码)浏览:933 |
复数求和 (C语言代码)浏览:915 |