#include<stdio.h> #include<math.h> main() { int a,b,c; float r1,r2,re,im,p,q,x,y; printf("enter the coeficiants of ur quadratic equation\n "); scanf("%d %d %d",&a,&b,&c); if(a==0) printf("this is not a quadratic equation"); else { p=b*b-4*a*c; if(p==0) { printf("there is only one root\n"); r1=-b/(2.0*a); printf("\tthe root is =%f",r1); } if(p<0) { q=-p; re=sqrt(q)/(2*a); im=-b/(2.0*a); printf("\tthe roots are imaginary\n"); printf("\troot 1= %f +i %f\n",re,im); printf("\troot 2=%f -i %f",re,im); } if(p>0) { x=(-b+sqrt(p))/(2*a); y=(-b-sqrt(p))/(2*a); printf("\nroot 1=%f",x); printf("\nroot 2=%f",y); } } }
Friday, 10 February 2012
how to solve quadratic equation
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment