.求教,C语言,求ax^2+by+c=0的解我的程序:#include "stdio.h"#include "math.h"void main(){ int a,b,c; float x1,x2,p; printf("please enter a b c\n"); scanf("%f,%f,%f",&a,&b,&c); p=pow(b,2)-4*a*c; if(p>0) {x1=(-b+sqrt(p))/(2*a); x2=(-b-sqrt(
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/20 03:29:22
.求教,C语言,求ax^2+by+c=0的解我的程序:#include "stdio.h"#include "math.h"void main(){ int a,b,c; float x1,x2,p; printf("please enter a b c\n"); scanf("%f,%f,%f",&a,&b,&c); p=pow(b,2)-4*a*c; if(p>0) {x1=(-b+sqrt(p))/(2*a); x2=(-b-sqrt(
.求教,C语言,求ax^2+by+c=0的解
我的程序:#include "stdio.h"
#include "math.h"
void main()
{
int a,b,c;
float x1,x2,p;
printf("please enter a b c\n");
scanf("%f,%f,%f",&a,&b,&c);
p=pow(b,2)-4*a*c;
if(p>0)
{x1=(-b+sqrt(p))/(2*a);
x2=(-b-sqrt(pow(b,2)-4*a*c))/(2*a);}
else if(p
.求教,C语言,求ax^2+by+c=0的解我的程序:#include "stdio.h"#include "math.h"void main(){ int a,b,c; float x1,x2,p; printf("please enter a b c\n"); scanf("%f,%f,%f",&a,&b,&c); p=pow(b,2)-4*a*c; if(p>0) {x1=(-b+sqrt(p))/(2*a); x2=(-b-sqrt(
你的错误:
abc要声明为float类型.
if分支语句写的比较混乱.
我帮你修改的代码为:
#include "stdio.h"
#include "math.h"
void main()
{
float a,b,c; //此处有改动
float x1,x2,p;
printf("please enter a b c\n");
scanf("%f,%f,%f",&a,&b,&c);
p=pow(b,2)-4*a*c;
if (p>0)
{
x1=(-b+sqrt(p))/(2*a);
x2=(-b-sqrt(pow(b,2)-4*a*c))/(2*a);
}
else if (p<=1e-6 && p>=-1e-6) //此处有改动
{
x1=-b/(2*a);
x2=-b/(2*a);
}
else //此处有改动
{
printf("this is error\n");
}
printf("%f,%f\n",x1,x2);
}
测试结果:
//谢谢采纳,希望对你有所帮助