c语言 算一元二次方程#include<stdio.h>#include<math.h>int main(){double p,q,x1,x2,disc,a,b,c;scanf("%lf,%lf,%lf",&a,&b,&c);disc=b*b-4*a*c;if (disc>0){p=-b/(2.0*a);q=(sqrt(disc))/(2.0*a);x1=p+q;x2=p-q;printf("x1=%lf\

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/26 15:21:04
c语言算一元二次方程#include<stdio.h>#include<math.h>intmain(){doublep,q,x1,x2,disc,a,b,c;scanf("%

c语言 算一元二次方程#include<stdio.h>#include<math.h>int main(){double p,q,x1,x2,disc,a,b,c;scanf("%lf,%lf,%lf",&a,&b,&c);disc=b*b-4*a*c;if (disc>0){p=-b/(2.0*a);q=(sqrt(disc))/(2.0*a);x1=p+q;x2=p-q;printf("x1=%lf\
c语言 算一元二次方程
#include<stdio.h>
#include<math.h>
int main()
{
double p,q,x1,x2,disc,a,b,c;
scanf("%lf,%lf,%lf",&a,&b,&c);
disc=b*b-4*a*c;
if (disc>0)
{
p=-b/(2.0*a);
q=(sqrt(disc))/(2.0*a);
x1=p+q;
x2=p-q;
printf("x1=%lf\tx2=%lf",x1,x2);
}
else if (disc=0)
{
p=-b/(2.0*a);
x1=p;
printf("x1=x2=%lf",x1);
}


else if(disc<0)
{
disc=0-disc;
p=-b/(2.0*a);
q=(sqrt(disc))/(2.0*a);
printf("x1=%lf+%lfi\n",p,q);
printf("x2=%lf-%lfi\n",p,q);
}
return 0;
}

c语言 算一元二次方程#include<stdio.h>#include<math.h>int main(){double p,q,x1,x2,disc,a,b,c;scanf("%lf,%lf,%lf",&a,&b,&c);disc=b*b-4*a*c;if (disc>0){p=-b/(2.0*a);q=(sqrt(disc))/(2.0*a);x1=p+q;x2=p-q;printf("x1=%lf\
//只一处有错,还有一个注意输入格式.
#include
#include
int main()
{
double p,q,x1,x2,disc,a,b,c;
scanf("%lf,%lf,%lf",&a,&b,&c);//特别注意:此处要求输入时a,b,c(三个数)之间用逗号隔开,而不是空格!
disc=b*b-4*a*c;
if(disc>0)
{
p=-b/(2.0*a);
q=(sqrt(disc))/(2.0*a);
x1=p+q;
x2=p-q;
printf("x1=%lf\tx2=%lf",x1,x2);
}
else if(disc=0)//只有此处有错,关系表达式的等于符号是"==",此句改为else if(disc==0);即可
{
p=-b/(2.0*a);
x1=p;
printf("x1=x2=%lf",x1);
}
else if(disc