puts "\ninput a number:" number = gets number = number.to_i begin puts "\ninput a base (min is 2 and max is 10):" base = gets base = base.to_i end while base < 2 or base >10 result = 0 i = 0 while number/base != 0 do remainder = number % base result += remainder * 10**i i += 1 number = number / base end result += number * 10**i puts "result is ", result
第一个输入一个十进制的数字,第二个输入基数(即几进制,大于1小于11),输入结果为转换后的结果,纯属娱乐,目前只实现了ruby版的。