Treino De Matematica 2 - Equacões de Segundo Grau

Script que gera um arquivo com equações de segundo grau para serem resolvidas e outro arquivo com as raízes de cada equação proposta.
Script to create a file with quadratic equations and another file with the solutions.

print("quantas questoes?")

numberquestions = io.read("*n")

deltpar1 = 25

--deltpar2 = 30

i = 1

while i < (numberquestions + 1) do

    a = math.random(deltpar1)

    b = math.random(deltpar1)

    c = math.random(deltpar1)

    delta = b*b - 4*a*c

    while delta < 0 do

        a = math.random(deltpar1)

        b = math.random(deltpar1)

        c = math.random(deltpar1)

        delta = b*b - 4*a*c

    end

    delta2 = math.pow(delta,(1/2))

    x1 = (-b + delta2)/(2*a)

    x2 = (-b - delta2)/(2*a)

    vdelta2 = math.floor(delta2)

    vx1 = math.floor(x1)

    vx2 =math.floor(x2)

    if delta2 == vdelta2 and x1 == vx1 and x2 == vx2 then

        --print("("..i..") raiz quadrada de delta igual a: "..delta2)

        --i = i + 1

        --x1 = (-b + delta2)/(2*a)

        --x2 = (-b - delta2)/(2*a)

        print("("..i..") "..a.."x^2 + "..b.."x + "..c.." = 0")

        print("resp questao ("..i..") ---> x1 = "..x1..", x2 = "..x2..", delta = "..delta..", raiz de delta = "..delta2)

        file = io.open("baskaratraining.txt","a+")

        file:write("("..i..") "..a.."x^2 + "..b.."x + "..c.." = 0 \n")

        file:close ()

        file = io.open("baskaratraining_results2.txt","a+")

        file:write("("..i..") x1 = "..x1..", x2 = "..x2..", delta = "..delta..", raiz de delta = "..delta2.."\n")

        file:close ()

        i = i + 1

        vi = math.mod(i,2)

        if vi == 0 then

            deltpar1 = deltpar1 - 2

        else

            deltpar1 = deltpar1 + 3

        end

    else

        i = i

    end

end

voltar(back)

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