Friday, October 14, 2011

Write a C program to find the roots of a quadratic equation.

#include<stdio.h>
#include<math.h>
main()
{
    float a,b,c,r1,r2;
    printf("Enter values for a,b,c for finding the roots of quadratic equation:\n");
    scanf("%f%f%f",&a,&b,&c);
    if(b*b>4*a*c)
    {
        r1=(-b+sqrt(b*b>4*a*c))/(2*a);
        r2=(-b-sqrt(b*b>4*a*c))/(2*a);
        printf("root1=%f\nroot2=%f\n",r1,r2);
    }
    else
    printf("Imaginary roots");
}

No comments:

Post a Comment