解题思路:(参看前三题题解)
根据题目条件找出规律;
用do-while语句设置开始条件;
利用函数设置双重条件;
#include<stdio.h>
#define N 50
int mother_cow[N];
void mother_cow2(int n);
int main()
{
int i=0,j;
mother_cow2(N);
int input[N];
do{
scanf("%d",&input[i]);
}while(input[i++]!=0);
for(j=0;j<i-1;j++)
{if(input[j]<4)
printf("%d\n",mother_cow[input[j]]);
else
printf("%d\n",mother_cow[input[j]-1]+mother_cow[input[j]-3]);
}
return 0;
}
void mother_cow2(int n)
{
int i;
for(i=0;i<n;i++)
{
if(i<4)
mother_cow[i]=i;
else
mother_cow[i]=mother_cow[i-1]+mother_cow[i-3];
}
0.0分
0 人评分
不知道哪里错了浏览:1145 |
C语言训练-计算1~N之间所有奇数之和 (C语言代码)浏览:655 |
【明明的随机数】 (C++代码)浏览:781 |
兰顿蚂蚁 (C++代码)浏览:1047 |
C语言程序设计教程(第三版)课后习题8.1 (C语言代码)浏览:531 |
蛇行矩阵 (C语言代码)浏览:536 |
简单的a+b (C语言代码)浏览:546 |
【偶数求和】 (C语言代码)浏览:431 |
C语言程序设计教程(第三版)课后习题8.4 (C语言代码)浏览:560 |
【偶数求和】 (C++代码)浏览:701 |