#include
#include
#include
int main(int argc, char *argv[])
{
double a,b,c,root,kai1,kai2;
if(argc<4) return 0;
a=atof(argv[1]); b=atof(argv[2]); c=atof(argv[3]);
printf("** The solution of a secondary equation:\n");
if (a==0){
printf("a is 0\n");
} else {
printf("\nEQUATION: %0.2lf*x^2 + %0.2lf*x + %0.2lf = 0\n",a,b,c);
root = b*b - 4*a*c;
if(root<0){
kai1 = -b / (2*a);
kai2 = sqrt(-root) / (2*a);
printf("\tx1 = %0.2lf+%0.2lfi, x2 = %0.2lf-%0.2lfi\n",
kai1,kai2,kai1,kai2);
} else {
kai1 = (-b+sqrt(root)) / (2*a);
kai2 = (-b-sqrt(root)) / (2*a);
printf("\tx1 = %0.2lf, x2 = %0.2lf\n",kai1,kai2);
}
}
}
|