Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that determines the roots of a quadratic equation ax^2 + bx + c

ID: 3775706 • Letter: W

Question

Write a program that determines the roots of a quadratic equation ax^2 + bx + c = 0 When the program runs, it should ask the user for the number of cases they want to calculate. Then it should use that number to set the for loop in the code. The constants a, b and c have to entered by the user. Then use the discriminant D D = b^2 - 4 ac If D>0, the program displays a message - The equation has two roots: and the roots are ####, ####' If D = 0t the program displays a message - 'The equation has one root and it is #####' If D

Explanation / Answer

fprintf(' enter number cases cases : ');

n=input('');

for i=1:n

fprintf(' enter a b c values ');

a=input('');

b=input('');

c=input('');

d=b*b-4*a*c;

if d==0

r=-b/(2*a);

fprintf('The equation has one root : and it is %d, %d',r,r);

elseif d>0

r1=(-b+sqrt(d))/(2*a);

r2=(-b-sqrt(d))/(2*a);

fprintf('The equation has two roots:and the roots are %d, %d',r1,r2);

else

fprintf('The equation has no real roots');

end

end

out put:

enter number cases cases   : 3

enter a b c values
2
8
8
The equation has one root : and it is -2, -2
enter a b c values
-5
3
-4
The equation has no real roots
enter a b c values
-2
7
4
The equation has two roots:and the roots are -5.000000e-001, 4>>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote