帮我编写一道c语言程序

来源:百度知道 编辑:UC知道 时间:2024/05/26 03:17:36
实现ax2+bx+c=0的方程求解。要求:当b2-4ac≥0 时,输出 x1=(-b+根号下b2-4ac)/2a x2=(-b-根号下b2-4ac)/2a 当b2-4ac<0 时,输出“No real root”。(不考虑a=0的情况。
#include <stdio.h>
#include <math.h>
void main()
{
double a,b,c,x1,x2;
printf("input a,b,c:\n");
scanf("%lf%lf%lf",&a,&b,&c);
if(b*b-4*a*c>=0)
x1=(sqrt(b*b-4*a*c)-b)/2*a,x2=(-sqrt(b*b-4*a*c)-b)/2*a;
else
printf("No real root");
printf("x1=%.2lf,x2=%.2lf\n",x1,x2);
}
大家看我这段程序有没有问题

#include <stdio.h>
#include <math.h>
void main()
{
float a,b,c,p,x1,x2;
printf("输入a,b,c的值\n");
scanf("%f%f%f",&a,&b,&c);
p=b*b-4*a*c;
if(p>=0)
{
x1=(-b+sqrt(p))/(2*a);
x2=(-b-sqrt(p))/(2*a);
printf("x1=%.2f\nx2=%.2f",x1,x2);
}
else printf("no real root");
}

#include <stdio.h>
#include <math.h>

int ercifangcheng(float a,float b,float c);

int main(void)
{
float x,y,z;
printf("please input the numbers:");
scanf("%f%f%f",&x,&y,&z);
ercifangcheng(x,y,z);
return 0;
}

int ercifangcheng(float a,float b,float c)
{
double disc,term1,term2,term;
disc=b*b-4*a*c;
term=sqrt(fabs(disc));
term1=-b/(2*a);
term2=term/(2*a);

if (a==0)
{
if(b==0)
p