C program to find roots of quadratic equation

Mr Coder September 16, 2012 7

C program to find roots of quadratic equation : In mathematics, quadratic equation is second degree univariate polynomial equation. A general quadratic equation can be represented by :

Quadratic Equation

where a, b and c are the coefficients of quadratic equation and a ≠ 0 . If a = 0 then it will be linear equations.

Now the solutions of quadratic equation can have distinct roots, equal roots or complex roots depending upon the value of discriminant.

Discriminant of a quadratic equation is an constant value equal to b^2 -4ac. Now,

If Discriminant>0, then quadratic equation will have distinct roots.

If Discriminant=0, then Quadratic equation will have equal roots.

If Discriminant<0, then Quadratic equation will have complex roots.

I have written a C program to find roots of quadratic equation which accepts coefficients of quadratic equation as input and  calculates and displays the roots of quadratic equation.

Platform : C Language

Compiler : Dev C++

C program to find roots of quadratic equation :


int main()
float a,b,c,x1,x2,disc;
printf("----------------made by C code champ ------------------------\n");
printf("\n  C Program for Calcualting roots of Quadratic Equation\n\n"); 
printf("Enter coefficient of X^2 : ");
printf("\nEnter coefficient of X^1 : ");
printf("\nEnter coefficient of X^0 : ");
/*Finding discriminant*/
/*distinct roots*/
printf("\nThe roots are distinct\n");
/*Equal roots*/
printf("\nThe roots are equal\n");
/*complex roots*/
printf("\nThe roots are complex.\n");
printf("The first root=%f+i%f\n",x1,x2);
printf("The second root=%f-i%f\n",x1,x2);

We hope you all have enjoyed the C program to find roots of quadratic equation. If you have any issues or concerns with the logic ask us in form of comments.


  1. Wiseman October 19, 2012 at 1:05 am - Reply

    A wonrdeful job. Super helpful information.

  2. Android os November 3, 2012 at 9:00 pm - Reply

    I every time emailed this website post page to all my contacts, as if like to read it afterward my links will too.

  3. Ariane Poinsett November 6, 2012 at 2:55 pm - Reply

    Nice post. I learn something new and challenging on websites I stumbleupon everyday. It will always be exciting to read articles from other writers and use something from their websites.

  4. Stand apart November 6, 2012 at 5:40 pm - Reply

    just beneath, are numerous totally not related sites to ours, however, they are surely worth going over.

  5. Sobhan January 31, 2013 at 10:52 am - Reply

    plz explain the code
    what is “fabs” meaning?

  6. Lokesh Singh January 31, 2013 at 1:06 pm - Reply

    Fabs function is function absolute value function defined under math.h. It is used to calculate absolute value of arg.
    Say num = -1234.00 then its absolute value will be 1234 i.e. fabs(num) =1234.

  7. shivam thakur December 8, 2013 at 11:19 am - Reply

    pls tell me c program

    * *
    * * *
    * * * *
    * * * * *
    * * * *
    * * *
    * *

Leave A Response »