Thursday, February 4, 2010

quardatic equation

// QUARDATIC EQUATION

#include
#include
#include
void main()
{
float a,b,c;
float d,x,x1,d1,root1,root2;
clrscr();
printf("Enter the follwing quation coefficients ax^2+bx+c \n");
scanf("%f%f%f",&a,&b,&c);
d=((b*b)-(4*a*c));
printf("\t\t**********OUT PUT**********\n");
if(d!=0)
{
 if(d>0)
 {
 root1=((-(b))+sqrt(d))-(2*a);
 root2=((-(b))-sqrt(d))-(2*a);
 printf("\nThe given equation are real and distint \n\troot1=%f\n\troot2=%f",root1,root2);
 }

 else
 {
 x=(-b)/(2*a);
 d1=(sqrt(-d)/(2*a));
 printf("\nThe given equation are imaginary\n");
 printf("\t%f+i %f\n",x,d1);
 printf("\t%f-i %f",x,d1);
  }
}
else
{
 printf("\nThe given equation are real and equal");
 x1=(-b)/(2*a);
 printf("\n\tThe roots are\n\t %f\n\t %f"  ,x1,x1);
}
getch();
}






No comments:

Post a Comment