Pages

Visitors

Thursday, 22 December 2011

Roots of a QE


Roots of a Quadratic Equation :

#include <stdio.h>
#include <conio.h>
#include <math.h>

void main()

{
    float disc,x1,x2; int a,b,c;

    printf ("enter a,b,c for ax^2+bx+c = 0: ");

    scanf ("%d%d%d", &a,&b,&c);

    disc = (b*b) - 4*a*c;

    x1 = (-b + sqrt(disc))/2*a;
    x2 = (-b - sqrt(disc))/2*a;

    if (disc >=0 )
    printf("roots are %f,%f.",x1,x2);

    else
    printf ("\nroots are imaginary");
      getch();
}

No comments:

Post a Comment