Roots of a quadratic function: Difference between revisions

Content added Content deleted
No edit summary
Line 850: Line 850:
<lang IS-BASIC>100 PROGRAM "Quadratic.bas"
<lang IS-BASIC>100 PROGRAM "Quadratic.bas"
110 INPUT PROMPT "a= ,b= ,c= ":A,B,C
110 INPUT PROMPT "a= ,b= ,c= ":A,B,C
140 LET D=B^2-4*A*C
120 LET D=B^2-4*A*C
150 SELECT CASE SGN(D)
130 SELECT CASE SGN(D)
160 CASE 0
140 CASE 0
170 PRINT "The single root is ";-B/2/A
150 PRINT "The single root is ";-B/2/A
180 CASE 1
160 CASE 1
190 LET F=(1+SQR(1-4*A*C/B^2))/2
170 PRINT "The real roots are ";(-B+SQR(D))/(2*A);"and ";(-B-SQR(D))/(2*A)
180 CASE -1
200 PRINT "The real roots are ";-F*B/A;"and ";-C/B/F
190 PRINT "The complex roots are ";-B/2/A;"+/- ";STR$(SQR(-D)/2/A);"*i"
210 CASE -1
200 END SELECT</lang>
220 PRINT "The complex roots are ";-B/2/A;"+/- ";STR$(SQR(-D)/2/A);"*i"
230 END SELECT</lang>


=={{header|J}}==
=={{header|J}}==