好玩的线上检测代码工具-codewars(1)
来源:互联网 发布:java变量初始化 编辑:程序博客网 时间:2024/05/22 01:36
检测环境:
http://www.codewars.com
基本描述:
Task:
Your task is to write a function which returns the sum of following series upto nth term(parameter).
Series: 1 + 1/4 + 1/7 + 1/10 + 1/13 + 1/16 +…
Rules:
You need to round the answer to 2 decimal places and return it as String.
If the given value is 0 then it should return 0.00
You will only be given Natural Numbers as arguments.
Examples:
SeriesSum(1) => 1 = “1.00”
SeriesSum(2) => 1 + 1/4 = “1.25”
SeriesSum(5) => 1 + 1/4 + 1/7 + 1/10 + 1/13 = “1.57”
NOTE: In PHP the function is called series_sum().
function series_sum($n) { // Your code here if($n == 0) { return '0.00'; } $res = 0; $n = floor($n); if($n == 1) { return '1.00'; } else { for($i = 1;$i <= 3*$n-2; $i = $i+3) { $res += 1/$i; } return (String) round($res, 2); }}
阅读全文
1 0
- 好玩的线上检测代码工具-codewars(1)
- 好玩的线上检测代码工具-codewars(2)
- 好玩的线上检测代码工具-codewars(3)
- 好玩的线上检测代码工具-codewars(4)
- 好玩的线上检测代码工具-codewars(5)
- 一段好玩的代码
- 好玩的java代码
- 一段好玩的代码
- 好玩的代码
- 前端开发调试线上代码的两款工具
- 好玩的webapp工具maka
- 呼唤QQ的代码,好玩
- 好玩的代码注释模板
- 【总结】一些好玩的工具汇总
- 辣子工具LSUtils:一些好玩的函数
- 一段好玩的修改网页的代码
- 好玩的代码读你的心
- 一道好玩的题的解题代码
- NG机器学习week5 Neural Networks: Learning
- bzoj 2882(最小表示法)
- Springmvc @interface注解的使用
- Android View部分消失效果实现
- Spring学习笔记—高级特性
- 好玩的线上检测代码工具-codewars(1)
- 【Oracle】NUMBER类型理解
- hdu6115 Factory(树上最近公共祖先)
- 该是回归的时候了
- Jetty Runner的使用
- git 的使用学习 0814
- Feel Good
- 行为识别-时间-概率模型
- intellij Idea 部署SpringMVC项目(一)