c语言编写一元2次方程.#include#includevoid main(){double a,b,c,x1,x2,d;scanf("%f,%f,%f",&a,&b,&c);d=b*b-4*a*c;x1=(-b+sqrt(d))/2;x2=(-b-sqrt(d))/2;if(d>0)printf("x1=%f,x2=%f\n",x1,x2);if(d=0)printf("x1=x2=%f\n",x1);if(d

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/27 20:42:54
c语言编写一元2次方程.#include#includevoidmain(){doublea,b,c,x1,x2,d;scanf("%f,%f,%f",&a,&b,&c);d=b*b-4*a*c;x1

c语言编写一元2次方程.#include#includevoid main(){double a,b,c,x1,x2,d;scanf("%f,%f,%f",&a,&b,&c);d=b*b-4*a*c;x1=(-b+sqrt(d))/2;x2=(-b-sqrt(d))/2;if(d>0)printf("x1=%f,x2=%f\n",x1,x2);if(d=0)printf("x1=x2=%f\n",x1);if(d
c语言编写一元2次方程.
#include
#include
void main()
{double a,b,c,x1,x2,d;
scanf("%f,%f,%f",&a,&b,&c);
d=b*b-4*a*c;
x1=(-b+sqrt(d))/2;
x2=(-b-sqrt(d))/2;
if(d>0)
printf("x1=%f,x2=%f\n",x1,x2);
if(d=0)
printf("x1=x2=%f\n",x1);
if(d

c语言编写一元2次方程.#include#includevoid main(){double a,b,c,x1,x2,d;scanf("%f,%f,%f",&a,&b,&c);d=b*b-4*a*c;x1=(-b+sqrt(d))/2;x2=(-b-sqrt(d))/2;if(d>0)printf("x1=%f,x2=%f\n",x1,x2);if(d=0)printf("x1=x2=%f\n",x1);if(d
这是我做的
#include
#include
void main() //主函数
{
float a,b,c,delta,x,x1,x2,realpart,imagpart; //定义a,b,c,delta,x,x1,x2,x3为浮点型
scanf("%f,%f,%f",&a,&b,&c); //输入二次方程系数a,b,c的值
delta=b*b-4*a*c;
if(fabs(a)>=1e-6) //以下为if语句
{
if(fabs(delta)1e-6)
{
 x1=(-b+sqrt(delta))/2/a;
 x2=(-b-sqrt(delta))/2/a;
 printf("x1=%f,x2=%f\n",x1,x2);//delta>0有两实根
}

else
{
realpart=-b/(2*a);
imagpart=sqrt(-delta)/(2*a);
printf("has complex roots:\n");
printf("%f+%f*i\n",realpart,imagpart);
printf("%f-%f*i\n",realpart,imagpart);//delta