人品增长

In a small town the population is p0 = 1000 at the beginning of a year. The population regularly increases by 2 percent per year and moreover 50 new inhabitants per year come to live in the town. How many years does the town need to see its population greater or equal to p = 1200 inhabitants?
  • 在一个小镇,人口在年初是p0 = 1000。 人口每年定期增长2%,并且每年有50多个新居民居住在该镇。 该镇需要多少年才能看到其人口大于等于p = 1200?
    • town镇、城镇、城市
    • population人口
    • beginning开始、开头、初期、开端、起头
    • regularly经常
    • increase增加、增长
    • percent百分
    • per每
    • moreover此外
    • more更多
    • over:.adv过度,.prep以上,.n多余、余额
    • inhabitants居民
    • come来、来到、过来
    • greater 更大的、优越、优胜
At the end of the first year there will be:
  • 在第一年末,将有:
    • will be将会

1000 + 1000 * 0.02 + 50 => 1070 inhabitants

At the end of the 2nd year there will be:

1070 + 1070 * 0.02 + 50 => 1141 inhabitants (number of inhabitants is an integer)居民人数为整数

At the end of the 3rd year there will be:

1141 + 1141 * 0.02 + 50 => 1213

It will need 3 entire years.
  • 这将需要3年的时间。
    • will将
    • entire 整个
More generally given parameters:
  • 通常给定参数
    • generally 通常
    • given 给、给定
    • parameters参数

p0, percent, aug (inhabitants coming or leaving each year), p (population to surpass)

inhabitants coming or leaving each year
  • 每年来或离开的居民
    • coming未来、来、过来
    • leaving离开、出发
    • Leaves树叶
    • each每、各、各个、各自
population to surpass
  • 人口要超过
    • surpass超过、超越、赛过、优于
the function nb_year should return n number of entire years needed to get a population greater or equal to p.
  • 函数nb_year应该返回使人口大于或等于p所需的整数n年。
    • should 应该、应当
    • entire整个
    • greater更大,优越,优胜
aug is an integer, percent a positive or null number, p0 and p are positive integers (> 0)
  • aug是整数,正数或空数的百分比,p0p是正整数(> 0)
    • integer整数
    • percent百分比
    • positive正
    • exam考试
example(例)

nb_year(1500, 5, 100, 5000) -> 15nb_year(1500000, 2.5, 10000, 2000000) -> 10

Note: Don't forget to convert the percent parameter as a percentage in the body of your function: if the parameter percent is 2 you have to convert it to 0.02.
  • 注意:不要忘记将百分比参数转换为函数体内的百分比:如果参数百分比为2,则必须将其转换为0.02。
    • note注意
    • none 没有
    • convert兑换、变换、转换
    • parameter参数
    • per每
    • percent百分
    • percentage百分比
    • body身体
  • [x] Fundamentals(基本原理)

code Analysis(代码分析)

源码

JS描述

//函数封装
function nb_year(p0,percent,aug,p){	
	var count = 0;//计数器
	while (p0 < p){
		++count;
		p0 = p0 + p0*(percent/100) + aug;
	}
	return count;
}
//测试代码
var p0 = 1000, percent = 2, aug = 50, p = 1200;
document.write(p0+'-->'+p+'需要'+nb_year(p0,percent,aug,p)+'年</br>');//3
var p0 = 1500, percent = 5, aug = 100, p = 5000;
document.write(p0+'-->'+p+'需要'+nb_year(p0,percent,aug,p)+'年</br>');//15
var p0 = 1500000, percent = 2.5, aug = 10000, p = 2000000;
document.write(p0+'-->'+p+'需要'+nb_year(p0,percent,aug,p)+'年</br>');//10
var p0 = 1500000, percent = 5, aug = 10000, p = 2000000;
document.write(p0+'-->'+p+'需要'+nb_year(p0,percent,aug,p)+'年</br>');//6
var p0 = 10, percent = 5, aug = 10, p = 50;
document.write(p0+'-->'+p+'需要'+nb_year(p0,percent,aug,p)+'年</br>');//4
//运行结果
1000-->1200需要3年
1500-->5000需要15年
1500000-->2000000需要10年
1500000-->2000000需要6年
10-->50需要4年

C语言描述

#include "stdio.h"
int nb_year(float p0,int percent,int aug,int p){	
	int count = 0;//计数器
	while (p0 < p){
		++count;
		p0 = p0 + p0*(percent/100.0) + aug;
	}
	return count;
}
int main()
{
	printf("%d\n",nb_year(1000,2,50,1200));//3
	printf("%d\n",nb_year(1500,5,100,5000));//15
	printf("%d\n",nb_year(1500000,2.5,10000,2000000));//12
	printf("%d\n",nb_year(1500000,5,10000,2000000));//6
	printf("%d\n",nb_year(10,5,10,50));//4
}

----------分割线----------

个人主页MrFlySand.github.io

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MrFlySand_飞沙

公众号【小知识酷】,搜索获取更

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值