SHARE
TWEET

Untitled

a guest Dec 11th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56. function round(num, numDecimalPlaces)
  57.   if numDecimalPlaces and numDecimalPlaces>0 then
  58.     local mult = 10^numDecimalPlaces
  59.     return math.floor(num * mult + 0.5) / mult
  60.   end
  61.   return math.floor(num + 0.5)
  62. end
  63. print("\n———————————————————————————————————————————————\n")
  64. a = io.read()
  65. print("a = " .. a .. "\n")
  66. b = io.read()
  67. print("b = " .. b .. "\n")
  68. c = io.read()
  69. print("c = " .. c .. "\n")
  70. print("\n———————————————————————————————————————————————\n")
  71. D = (b*b) - (4*a*c)
  72. print("D = " .. D)
  73. print("\n———————————————————————————————————————————————\n")
  74. sqrt = math.sqrt(math.abs(D))
  75. if(D > 0) then
  76. -- 2
  77. x1 = round(((b*-1)-sqrt)/(2*a), 3)
  78. if(x1 == 0.333) then x1 = "1/3" end
  79. x2 = round(((b*-1)+sqrt)/(2*a), 3)
  80. if(x2 == 0.333) then x2 = "1/3" end
  81. print("          " .. b*-1 .. " - √" .. D .. " \nx1 = —————————————————— = " .. x1 .. " \n             " .. 2*a .. "\n")
  82. print("          " .. b*-1 .. " + √" .. D .. " \nx2 = —————————————————— = " .. x2 .. " \n             " .. 2*a .. "")
  83. elseif(D < 0) then
  84. print("корней нет.")
  85. elseif(D == 0) then
  86. x = round((b*-1)/(2*a), 3)
  87. if(x == 0.333) then x = "1/3" end
  88. print("          " .. b*-1 .. "\nx = —————————————————— = " .. x .. " \n           " .. 2*a .. "\n")
  89. end
  90. print("\n———————————————————————————————————————————————\n")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top