(30%) Write a pseudocode algorithm to solve the following problem: Given three n
ID: 3872185 • Letter: #
Question
(30%) Write a pseudocode algorithm to solve the following problem: Given three numbers a, b and c corresponding to the constants of a second degree polynomial, that is, a polynomial of the form a*x2+b*x c, find the roots of such a olynomial; .e., write a pseudocode algorithm that receives a, b and c as input and outputs the roots of the corresponding polynomial It is known that second degree polynomials may have up to two roots depending on the value of the discriminant. The discriminant is D = b. (4*a*c). If D 0 the polynomial has two roots, they are (-b SquareRoot(D))/(2*a) and (-b- SquareRoot(D))/(2*a).Explanation / Answer
Pseudo Code Algo:
START MAIN
Initialize ROOT variable to 0.
Read constants a,b and c for 2nd degree polynomial
Calculate Discriminant D = b*b - (4 * a * c)
IF D < 0
Print 'No roots available for given polynomial'
ELSE IF (D == 0)
Calculate ROOT = -( b / (2 * a) )
Print 'Only 1 Root is available for this polynomial and it is ' ROOT.
ELSE
Print "This polynomial has 2 roots"
Calculate 1st ROOT = -b + SQRT(D) / (2 * a)
Print "Root 1 of the polynomial is" ROOT
Calculate 2nd ROOT = -b - SQRT(D) / (2 * a)
PRINT "Root 2 of the polynomial is " ROOT
END MAIN
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.