function solveQuadratic(a, b, c) if a == 0 then if b == 0 then if c ~= 0 then print("No solution") else print("Infinite solutions") end else print("The root of the given linear function is " .. (-c / b)) end return end local D = b^2 - 4*a*c if D < 0 then print("No real roots") elseif D == 0 then print("One real root: " .. (-b / (2*a))) else local x1 = (-b - math.sqrt(D)) / (2*a) local x2 = (-b + math.sqrt(D)) / (2*a) print("Roots: " .. x1 .. " and " .. x2) end end function findFactorial(n) local F = 1 for i = 1, n do F = F * i end print("Result is: " .. F) return F end function fibonacciSequence(n) local a, b = 1, 2 io.write("Fibonacci Sequence: ") for i = 1, n do io.write(a .. " ") local c = a + b a = b b = c end print() end function collatz(n) io.write("Collatz sequence: ") while n > 1 do io.write(n .. " ") if n % 2 == 0 then n = n / 2 else n = n * 3 + 1 end end print(1) end print("Do you want to solve a quadratic function? (Yes/No)") local answer = io.read():lower() if answer == "yes" then print("Enter a:") local a = tonumber(io.read()) print("Enter b:") local b = tonumber(io.read()) print("Enter c:") local c = tonumber(io.read()) solveQuadratic(a, b, c) else print("Do you want to find a factorial number? (Yes/No)") answer = io.read():lower() if answer == "yes" then print("Write a number:") local m = tonumber(io.read()) findFactorial(m) else print("Do you want to generate the first N Fibonacci numbers? (Yes/No)") answer = io.read():lower() if answer == "yes" then print("Write a number:") local n = tonumber(io.read()) fibonacciSequence(n) else print("Do you want to generate Collatz Conjecture? (Yes/No)") answer = io.read():lower() if answer == "yes" then print("Write a number:") local h = tonumber(io.read()) collatz(h) else print("Abort") end end end end