RosettaCodeData/Task/Trabb-Pardo-Knuth-algorithm/Pluto/trabb-pardo-knuth-algorithm...

23 lines
471 B
Plaintext

require "io2"
local fmt = require "fmt"
local f = |x| -> math.sqrt(math.abs(x)) + 5 * x * x * x
local s = {}
print("Please enter 11 numbers:")
local count = 0
repeat
s[++count] = io.readNum(string.format(" Number %-2d : ", count))
until count == 11
s:reverse()
print("\nResults:")
for s as item do
local fi = f(item)
if fi <= 400 then
fmt.print(" f(%6.3f) = %7.3f", item, fi)
else
fmt.print(" f(%6.3f) = overflow", item)
end
end