首页 > 其他 > 详细

Epic - Decimal Number

时间:2015-06-13 09:42:29      阅读:242      评论:0      收藏:0      [点我收藏+]

Let the user enter a decimal number. Therange allowed is 0.0001 to 0.9999. Only four decimal places are allowed. Theoutput should be an irreducible fraction. E.g.: If the user enters 0.35,the irreducible fraction will be 7/20.

等于找与10000的公约数

def fraction(d)
  x = d*10000
  gcd = findgcd(x,10000)
  (x/gcd).to_i.to_s + / + (10000/gcd).to_i.to_s
end

def findgcd(a,b)
  return a if b == 0
  findgcd(b,a%b)
end

 

Epic - Decimal Number

原文:http://www.cnblogs.com/lilixu/p/4572954.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!