The problem Write a program to calculate the roots of a quadratic
equation of the form:
The roots are given by the following formula
The algorithm
- READ values of a, b and c,
- if a is zero then stop as we do not have a quadratic,
- calculate value of discriminant
- if D is zero then there is one root: ,
- if D is > 0 then there are two real roots:
and ,
- if D is < 0 there are two complex roots:
and ,
- PRINT solution.
OR
Click here for the Flowchart of this Click Here
ALGORITHM TO SOLVE QUADRATIC EQUATION
1.integer a,b,c;
2.float d,r1,r2,r3,r4,r;
3.print ‘Enter values of a,b,c of a quadratic equation:’;
4.read a,b,c;
5.value of a,b,c is transferred to function ‘quad’and body of function is:
6.d b x b-4 x a x c;
7.if(d<0)
8.print ‘Value of Discriminant is negative’;
9.else
10.if(d=0)
11.print ‘Roots are real’
12.r=-b/2*a;
13.print ‘First and Second root of equation:’,r;
14.else
15.r1 -b+sqrt(d);
16.r2 2*a;
17.r r1/r2;
18.r3 -b-sqrt(d);
19.r4 r3/r2;
20.print ‘First root of equation: ’, r;
21.print ‘Second root of equation: ’, r4;
Sweet
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteJazzakum Allahu Khairan
ReplyDeleteReally like your courage to have this Blog
Lovely
ReplyDelete@Taofeek, thanks
ReplyDelete