Resolucao De Equacao De Segundo Grau Baskara 2

É preciso que esteja instalado GNUPlot para que se visualize os gráficos das parábolas.

i = 1
while i == 1 do
    print("ax^2 + bx + c = 0")
    print("digite o termo a: ")
    a = io.read("*n")
    print("digite o termo b: ")
    b = io.read("*n")
    print("digite o termo c: ")
    c = io.read("*n")
    delta = math.pow(b,2) - 4*a*c
    if delta < 0 then
        print("Nao há raiz real, delta = "..delta)
        file = io.open("curv.p","w+")
        file:write("#ploting script created by baskara.lua \n")
        file:write("set terminal x11 \n")
        file:write("reset \n")
        file:write("plot "..a.."*x**2 + "..b.."*x + "..c.." \n")
        file:write("pause -1")
        file:close ()
        file2 = io.open("curv.sh","w+")    
        file2:write("gnuplot curv.p")
        file2:close()
        os.execute("chmod +x curv.sh")
        os.execute("./curv.sh")
        print("deseja resolver mais uma equacao? (1) sim (2) nao")
        i = io.read("*n")
    else
        x1 = (-b + math.pow(delta,(1/2)))/(2*a)
        x2 = (-b - math.pow(delta,(1/2)))/(2*a)
        print("x1 = "..x1..", x2 = "..x2..", delta = "..delta)
        file = io.open("curv.p","w+")
        file:write("#ploting script created by baskara.lua \n")
        file:write("set terminal x11 \n")        
        file:write("reset \n")
        file:write("plot "..a.."*x**2 + "..b.."*x + "..c.." \n")
        file:write("pause -1")
            file:close ()
        file2 = io.open("curv.sh","w+")    
        file2:write("gnuplot curv.p")
        file2:close()
        os.execute("chmod +x curv.p")
        os.execute("./curv.sh")    
        print("deseja resolver mais uma equacao? (1) sim (2) nao")
        i = io.read("*n")    
    end
end

voltar(back)

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.