Thursday, March 31, 2011

Find roots of Quadratic equation



#include< math.h >
void main()
{
float r1,r2;
int a,b,c,d;
clrscr();
printf("enter value of a,b,c as ax^2+bx+c=0 ");
scanf("%d%d%d",&a,&b,&c);
d=pow(b,2)-4*a*c;
if(d<=0)
printf("roots are imaginary");
else
{
r1=(-b+sqrt(d))/(2*a);
r2=(-b-sqrt(d))/(2*a);
printf("root1=%f\nroot2=%f",r1,r2);
}
getch();
}

No comments:

Post a Comment