알고리즘 & 자료구조/알고리즘&자료구조
근의 공식 알고리즘 소스코드
3DMP
2012. 11. 2. 17:27
oid QuadraticEquation(double A,double B,double C)
{
if ( A == 0 )
{
printf("This equation is not Quadratic\n");
return ;
}
double Temp ;
Temp = B*B - 4*A*C ;
if ( Temp >= 0 )
{
double ans1,ans2 ;
ans1 = ( -1*B + sqrt(Temp) ) / ( 2*A ) ;
ans2 = ( -1*B - sqrt(Temp) ) / ( 2*A ) ;
printf("Two Real Roots: x1 = %f x2 = %f\n",ans1,ans2);
}
else
{
double real , complex ;
real = ( -1*B ) / ( 2*A ) ;
complex = sqrt(-1*Temp) / ( 2*A ) ;
printf("Complex Conjugate Roots :\n");
printf("x1,2 = %f +- %f i \n",real,complex);
}
}
반응형