mysql怎麼輸出函式執行結果_task執行的函式是怎麼從driver傳給executor的?
阿新 • • 發佈:2020-12-27
技術標籤:printfloadrunnercanvas封裝codec
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
是整數,正數或空數的百分比,p0
和p
是正整數(> 0)- integer整數
- percent百分比
- positive正
- exam考試
example(例)
nb_year(1500, 5, 100, 5000) -> 15
nb_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
}