# Java母牛每年生一头小牛,C++&C语言 -> //有一头母牛，它每年年初生一头小母牛。每头小母牛从第四个年头开始，每年年初也生一头小母牛。请编程实现在第n年的时候，共有多少头母牛？...

/*    a                  b                          c       d

1  5                   5                    1

2  5                   5+5                2     1

3  5                    5+5+5            3     2     1

4  5+5                10+5+5                  3     2      1

5  10+5=15            15+10+5                   3      2     1

6  10+5+5=20          20+15+10                       3      2

7  20+10=30                                                           3                                             30+20+15

8  20+10+15=45                                                                                                    45+30+20

9  20+10+15+20=65                                                                                              65+45+30

10 20+10+15+20+30=95                                                                                       95+65+45

11 20+10+15+20+30+45=140                                                                               140+95+65

12 20+10+15+20+30+45+65=205                                                                         205+140+95

13 20+10+15+20+30+45+65+95=300                                                                   300+205+140

14 20+10+15+20+30+45+65+140=440                                                                 440+300+205

15 20+10+15+20+30+45+65+140+205=645                                                         645+440+300

16 20+10+15+20+30+45+65+140+205+300=745                                                 745+645+440

17 20+10+15+20+30+45+65+140+205+300+440=1185                                       1185+745+645

18 20+10+15+20+30+45+65+140+205+300+440+645=1830                               1830+1185+745

19 20+10+15+20+30+45+65+140+205+300+440+645+745=2575                       2575+1830+1185

20 20+10+15+20+30+45+65+140+205+300+440+645+745+1185=3760             3760+2575+1830

21 20+10+15+20+30+45+65+140+205+300+440+645+745+1185+1830=5590   5590+3760+2575

*/

//#include"stdio.h"

#include

void add(int a,int aa1,int i1,int aa2,int i2,int aa3,int i3,int d)

{  int ab1=0,ab2=0,ab3=0,k1=0,k2=0,k3=0,x=0,x1=0,y=0,total=0,nd=0;

y=a; x1=aa3;

if(i1>=1&&i1<=d+1){

if(i1==1&&i2==0){

x=y;ab1=aa1;ab2=y;k2=i1;ab3=0;k3=i2;x=y;k1=i1+1;

//       printf("x=%d ab1=%d k1=%d ab2=%d k2=%d ab3=%d k3=%d\n",x,ab1,k1,ab2,k2,ab3,k3);

cout<

}

if(i1==2&&i2==1&&i3==0){

ab2=y;k2=i1;ab3=y;k3=i2;x=y;k1=i1+1;

//        printf("x=%d ab1=%d k1=%d ab2=%d k2=%d ab3=%d k3=%d\n",x,ab1,k1,ab2,k2,ab3,k3);

cout<

}

if(i1==3&&i2==2&&i3==1){

x=y;ab1=x;k1=1;ab2=y;k2=i1;ab3=y;k3=i2;

//      printf("x=%d ab1=%d k1=%d ab2=%d k2=%d ab3=%d k3=%d \n",x,ab1,k1,ab2,k2,ab3,k3);

cout<

}

else{           //  a=x   ab1=x1

if(i1==1&&i2==3&&i3==2){

x=y+aa3;ab1=x;k1=i1+1;ab2=aa1;k2=1;ab3=aa2;k3=i3+1;

//           printf("x=%d ab1=%d k1=%d ab2=%d k2=%d ab3=%d k3=%d\n",x,ab1,k1,ab2,k2,ab3,k3);

cout<

} //x=total;x1=total;

if(i2==1&&i3==3&&i1==2){

x=y+aa3;ab1=x;k1=i1+1;ab2=aa1;k2=i2+1;ab3=aa2;k3=1;

//         printf("x=%d ab1=%d k1=%d ab2=%d k2=%d ab3=%d k3=%d\n",x,ab1,k1,ab2,k2,ab3,k3);

cout<

}

if(i3==1&&i2==2&&i1==3){

x=y+aa3;ab1=x;k1=1;ab2=aa1;k2=i2+1;ab3=aa2;k3=i3+1;

//        printf("x=%d ab1=%d k1=%d ab2=%d k2=%d ab3=%d k3=%d\n",x,ab1,k1,ab2,k2,ab3,k3);

cout<

}

}

nd=d-1;

//      printf("Cow total is:%d %d\n",10-d+1,x);

cout<

}

} void main(){

int n=5,j1=5,i1=1,j2=0,i2=0,j3=0,i3=0,ct=10;   //n：开始拥有母牛总数，j1：第一批新增小牛数，i1：第一批新增小牛生长年份，j2：第二批新增的小牛数，i2：第二批新增的小牛数生长年份，

//j3：第三批新增的小牛数，i3：第三批新增的小牛生长年份;ct：生长总年份。

• 0
点赞
• 0
收藏
觉得还不错? 一键收藏
• 0
评论
07-27 7489
08-22 1809
04-03 573
09-06
01-17
01-17
04-24
01-14 9863
10-12 310

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、付费专栏及课程。