Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function round(num, numDecimalPlaces)
- if numDecimalPlaces and numDecimalPlaces>0 then
- local mult = 10^numDecimalPlaces
- return math.floor(num * mult + 0.5) / mult
- end
- return math.floor(num + 0.5)
- end
- print("\n———————————————————————————————————————————————\n")
- a = io.read()
- print("a = " .. a .. "\n")
- b = io.read()
- print("b = " .. b .. "\n")
- c = io.read()
- print("c = " .. c .. "\n")
- print("\n———————————————————————————————————————————————\n")
- D = (b*b) - (4*a*c)
- print("D = " .. D)
- print("\n———————————————————————————————————————————————\n")
- sqrt = math.sqrt(math.abs(D))
- if(D > 0) then
- -- 2
- x1 = round(((b*-1)-sqrt)/(2*a), 3)
- if(x1 == 0.333) then x1 = "1/3" end
- x2 = round(((b*-1)+sqrt)/(2*a), 3)
- if(x2 == 0.333) then x2 = "1/3" end
- print(" " .. b*-1 .. " - √" .. D .. " \nx1 = —————————————————— = " .. x1 .. " \n " .. 2*a .. "\n")
- print(" " .. b*-1 .. " + √" .. D .. " \nx2 = —————————————————— = " .. x2 .. " \n " .. 2*a .. "")
- elseif(D < 0) then
- print("корней нет.")
- elseif(D == 0) then
- x = round((b*-1)/(2*a), 3)
- if(x == 0.333) then x = "1/3" end
- print(" " .. b*-1 .. "\nx = —————————————————— = " .. x .. " \n " .. 2*a .. "\n")
- end
- print("\n———————————————————————————————————————————————\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement