An easy problem for this fine Tuesday. Your goal is to create a function that takes in an integer. Then you must print out that integer in scientific notation. For example:
10000 = 1 x 104
Feel free to assume the integer input will always be greater than 0.
Comments:
Derek - 9 years, 11 months ago
In Ruby:
reply permalink
Derek - 9 years, 11 months ago
ah crap.
reply permalink
Derek - 9 years, 11 months ago
Third time's the charm.
ruby def sci(i) mant = "" e = 0 while i >= 10 d = i%10 mant = "#{d}#{mant}" unless mant.empty? and d == 0 i /= 10 e += 1 end mant = "0" if mant.empty? "#{i}.#{mant} x 10^#{e}" end
reply permalink
Derek - 9 years, 11 months ago
Clearly I need more coffee.
reply permalink
Max Burstein - 9 years, 11 months ago
Needs more coffee script haha, Nicely done!
reply permalink