Tuesday, September 27, 2011

C Program To Solve A Quadratic Equation

Variables used
a,b,c-The values of eqn
d-Value to find existance of real root
r1,r2-Roots of eqn


Program


#include<stdio.h>
main()
{
int a,b,c,d ;
float r1,r2;
printf("Enter the values of a b c");
scanf ("%d%d%d",&a,&b,&c);
d=(b*b)-(4*a*c);
if(d==0)
{
printf("The roots are real ,equal");
r1=-b/(2*a);
r2=r1;
printf("Roots are %f%f",r1,r2);
}
if(d>0)
{
printf("The roots are real unequal");
r1=(-b+sqrt(d)/(2*a);
r2=(-b-sqrt(d)/(2*a);
printf("Roots are %f%f",r1,r2);
if(d<0)
{
printf("Roots are imaginary");
}
}


Output


Enter the values of a b c
1 4 4
The roots are real ,equal
Roots are 2 2



No comments:

Post a Comment