A program to find the roots of a quadratic equation

REM A program to find the roots of a quadratic equation ax2+bx+c=0, when the value of a, b and c are given. (QBasic Code)

CLS
INPUT "Enter the value of a"; a
INPUT "Enter the value of b"; b
INPUT "Enter the value of c"; c
k = (b ^ 2 - 4 * a * c)
IF k > 0 THEN
    x1 = (-b + k ^ (1 / 2)) / (2 * a)
    x2 = (-b - k ^ (1 / 2)) / (2 * a)
    PRINT "The first root is:"; x1
    PRINT "The second root is:"; x2
ELSE
    PRINT "The roots are imaginary."
END IF
END

Share :

Twitter
Back To Top

facebook main

counter

Powered by Blogger.