VmatrixOJ--Fishes in the pearl river

8 篇文章 0 订阅
8 篇文章 0 订阅

 

Description

Suppose there are X fishes in the pearl river currently, and the number of fishes decreases by Y every year.

Please write a program to compute after how many years do the number of fishes decrease to half of their current number, and how many years do the number decrease to one tenth of the current number.

有关专家十分关注珠江渔业资源的问题。目前珠江中大约有X条鱼,平均每年以y%的速度减少。请编写一个程序,计算在多少年之后鱼的数目下降到目前的一半?多少年后下降到目前的十分之一?

Input Format

A line that contains X and Y.

X is an integer between 1000 to 10000000, Y is a floating number between 0.01 to 1.0

Output Format

How many years will the fishes decease to half, How many years will the fishes decease to one tenth

Sample Input

800000 0.50

Sample Output

1 4

Hint

用%f读取第二个参数。

C--Code:

#include<stdio.h>
int main()
{
	int yu,yu2,fish,fish2;
	float lv;
	int year=0,year2=0;
	scanf("%d%f",&yu,&lv);
	fish=yu;fish2=yu;
	for(year=1;;year++)
	{
		fish=fish*(1-lv);
		if(fish<=(yu/2))
	{
			printf("%d ",year);break;
	}} 
	for(year2=1;;year2++)
	{
		fish2=fish2*(1-lv);
		if(fish2<(yu/10))
	{
			printf("%d\n",year2);break;}
	}
}
	

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值