| 网站首页 | 业界新闻 | 群组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛

已结贴   问题点数：20  回复次数：3

n=0表示输入数据的结束，不做处理。

2
4
5
0

2
4
6

#include<stdio.h>

int main()
{
int n;
int i,j,k;
scanf("%d",&n);
while(n>0)
{
k=2;
j=4;
if(n<5)
printf("%d\n",n);
else
{
for(i=4;i<n;i++)
{

j=j+k;
k++;

}
printf("%d\n",j);
}

scanf("%d",&n);

}
return 0;

}

得分:7

得分:7

#include<stdio.h>

int main()
{
int n,cow,calf=0,ox;     //年数，母牛数，小牛数,总数
printf("请输入年数：");
scanf("%d",&n);
while(n>0)
{
int i;  //循环变量
for(i=0;i<=n;i++)
{
if(i<4)     //4年内
{
cow=1;  //内母牛数不变
calf=i; //小牛数量逐年+1
}
else        //4年后
{
cow=i-2;    //母牛数逐年+1
calf=i;     //小牛数逐年+1
}
}
ox=cow+calf;
printf("母牛总数为%d\n",ox);
printf("请输入年数：");
scanf("%d",&n);
}
return 0;

}

得分:7

#include <stdio.h>

int main( void )
{
unsigned a = 1;
unsigned b = 0;
unsigned c = 0;

for( unsigned i=1; i<=50; ++i )
{
printf( "year %u: %u cow(s)\n", i, a+b+c );

unsigned t = a;
a += b;
b = c;
c = t;
}
}

year 1: 1 cow(s)
year 2: 2 cow(s)
year 3: 3 cow(s)
year 4: 4 cow(s)
year 5: 6 cow(s)
year 6: 9 cow(s)
year 7: 13 cow(s)
year 8: 19 cow(s)
year 9: 28 cow(s)
year 10: 41 cow(s)
year 11: 60 cow(s)
year 12: 88 cow(s)
year 13: 129 cow(s)
year 14: 189 cow(s)
year 15: 277 cow(s)
year 16: 406 cow(s)
year 17: 595 cow(s)
year 18: 872 cow(s)
year 19: 1278 cow(s)
year 20: 1873 cow(s)
year 21: 2745 cow(s)
year 22: 4023 cow(s)
year 23: 5896 cow(s)
year 24: 8641 cow(s)
year 25: 12664 cow(s)
year 26: 18560 cow(s)
year 27: 27201 cow(s)
year 28: 39865 cow(s)
year 29: 58425 cow(s)
year 30: 85626 cow(s)
year 31: 125491 cow(s)
year 32: 183916 cow(s)
year 33: 269542 cow(s)
year 34: 395033 cow(s)
year 35: 578949 cow(s)
year 36: 848491 cow(s)
year 37: 1243524 cow(s)
year 38: 1822473 cow(s)
year 39: 2670964 cow(s)
year 40: 3914488 cow(s)
year 41: 5736961 cow(s)
year 42: 8407925 cow(s)
year 43: 12322413 cow(s)
year 44: 18059374 cow(s)
year 45: 26467299 cow(s)
year 46: 38789712 cow(s)
year 47: 56849086 cow(s)
year 48: 83316385 cow(s)
year 49: 122106097 cow(s)
year 50: 178955183 cow(s)

• 4
• 1/1页
• 1

Powered by Discuz, Processed in 0.844925 second(s), 8 queries.
Copyright©2004-2019, BCCN.NET, All Rights Reserved