Like Share 153 people like this. Sign Up to see what your friends like. Follow @CodingBotBlog
Select Language
Pow ered by
Translate
Hi everyone In this post, we're going how to write a C program to calculate the roots of a quadratic equation. As we know that a quadratic equation is of a form like:
ax^2+bx+c=0
So we won't go into much details. Also you guys must be knowing to calculate the roots of a quadratic equation directly, having formula:
4 2 4 3 4 4
g e t c h ( ) ; }
Program Explanation:
The program is self explanatory in itself. First we take the coefficients of the quadratic equation as
Enjoy this page? Like us on Facebook! input from the user. Then on the basis of its determinant,i.e, b^2 - 4*a*c, if its greater than 0 or Like 153 equal to 0 or less than 0. In each of the case, we can get different types of roots, Unique, Equal or Complex respectively. Using the formula as I described in the beginning of this post, we calculate roots, with an exception in case of complex roots, whereby, we have to find real and imaginary parts of the roots individually, using the formula: Real Part = -b/(2*a) Imaginary Part = sqrt(-x)/(2*a) -> Since determinant is negative here, we make it positive by multiplying an extra '-'.
Program Output:
P l e a s eC o m m e n tI fY o uL i k e dT h eP o s t .
Do you like this post? Please link back to this article by copying one of the codes below. URL:
h t t p : / / w w w . c o d i n g b o t . n e t / 2 0 1 3 / 1 1 / c a l c u l a t e r o o t s o f q u a d r a t i c e q u a t i o n . h t m l