BlogUpp!

Sunday, May 6, 2012

A Quadratic Equation Solver - The Algorithm and Flow Chart

A Quadratic Equation Solver - The Algorithm

The problem Write a program to calculate the roots of a quadratic equation of the form:

displaymath24490

The roots are given by the following formula

displaymath24491

The algorithm

  1. READ values of a, b and c,
  2. if a is zero then stop as we do not have a quadratic,
  3. calculate value of discriminant tex2html_wrap_inline24506
  4. if D is zero then there is one root: tex2html_wrap_inline24510 ,
  5. if D is > 0 then there are two real roots: tex2html_wrap_inline24516 and tex2html_wrap_inline24518 ,
  6. if D is < 0 there are two complex roots: tex2html_wrap_inline24524 and tex2html_wrap_inline24526 ,
  7. 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;
 




Quadratic

1 comment: