How do l write complete qbasic program to compute quadratic equation whose sides are A B C and print out your result?

1 answer

Answer

1060396

2026-08-14 06:55

+ Follow

Exercise : Write a program to solve quadratic equations (ax^2 + bx + c), using a subroutinesub quadratic(a as double, b as double, c as double, indicator as long, root1 as double, root2 as double)

Input parameters are a, b, c.

Output parameters are :indicator (= 0 , two identical roots, = 1, two distinct real roots, = 2 , complex roots )

For real roots : they are stored in "root1" and "root2".

For complex roots : root1 = real part, root2 = imaginary part.

Ans : DEFLNG I-N DEFDBL A-H, O-Z L20: INPUT " Coefficients a,b,c (a*x^2+b*x+c) "; a, b, c CALL quadratic(a, b, c, iflag, r1, r2) IF iflag = 0 THEN PRINT "2 Identical roots "; r1 ELSEIF iflag = 1 THEN PRINT "2 distinct real roots "; r1; r2 ELSE PRINT "Complex root" PRINT "real part "; r1; "imaginary part "; r2 END IF GOTO L20 END SUB quadratic (a AS DOUBLE, b AS DOUBLE, c AS DOUBLE, indicator AS LONG, root1 AS DOUBLE, root2 AS DOUBLE) rem rem Input parameters: rem a*x*x + b*x + c rem rem Output parameters: rem indicator = 0 two identical roots, = 1 two distinct real roots, = 2 , complex roots. rem root1, root2 stores the real and imaginary part when complex roots occur. rem discrim = b * b - 4. * a * c IF discrim > 0 THEN dummy = SQR(discrim) indicator = 1 root1 = (-b + dummy) / (2. * a) root2 = (-b - dummy) / (2. * a) ELSEIF discrim = 0 THEN indicator = 0 root1 = -b / (2. * a) root2 = root1 ELSE indicator = 2 dummy = SQR(-discrim) root1 = -b / (2. * a) root2 = dummy / (2. * a) END IF END SUB

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.