代丽君


私信TA

用户名:dlj199838

访问量:13279

签 名:

我爱代码代码爱我

等  级
排  名 2831
经  验 2061
参赛次数 0
文章发表 20
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

解题思路:(参看前三题题解)

  1. 根据题目条件找出规律;

  2. 用do-while语句设置开始条件;

  3. 利用函数设置双重条件;

#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 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区