共回答了21个问题采纳率:85.7%
应该是Axx+Bx+C=0的根吧,我这写了个C语言的代码,至于第一步和第二步你还是看着代码自己完成吧,总不能完全依赖别人是吧...
// Solve Equation.cpp :Defines the entry point for the console application.
//
#include
#include
double a,b,c;
void initialize();//初始化工作
void Process();//求解过程
int main(int *argc,int *argv[])
{
int i;
char choice;
do{
i=0;
initialize();
Process();
printf("t go on?(y/n)n");
getchar();
scanf("%c",&choice);
if((choice=='y')||(choice=='Y'))
i=1;
}while(i);
return 0;
}
void initialize()
{
printf("-------------axx+bx+c=0----------------n");
printf("please input the factors:n");
printf("a=");
scanf("%lf",&a);
printf("b=");
scanf("%lf",&b);
printf("c=");
scanf("%lf",&c);
}
void Process()
{
double dt;//判别式
double x1,x2;
x1=x2=0;
dt=b*b-4*a*c;
if(0==a)
{
if(0==b)
printf("error:'a' and 'b' can`t be both zero!");
else if(0!=c)
printf("tX=%lfn-------the quation has only one rootn",-b/c);
else
printf("tX=0n-------the quation has only one rootn");
}
else
{
if(dt>=0)
{
dt=sqrt(dt);
x1=(-b+dt)/(2*a);
x2=(b+dt)/(2*a);
printf("tX1=%lf",x1);
printf("ntX2=%lf",x2);
printf("n-------the quation has two real root.");
}
else
{
dt=sqrt(-dt);
dt=dt/(2*a);
x1=(-b)/(2*a);
x2=b/(2*a);
printf("tX1=%lf+j%lf",x1,dt);
printf("ntX2=%lf-j%lf",x2,dt);
printf("n-------the quation has two imaginary rootn");
}
}
}
1年前
4