qq_33859550 于 2016.02.21 14:45 提问

vc 编程老是出现error

#include "stdafx.h"
#include "math.h"

int main(int argc, char* argv[])
{ double a,b,c,x1,x2,m,temp;
scanf("%lf %lf %lf",&a,&b,&c);
m=b*b-4*a*c;
x1=(sqrt(m)-b)/(2*a);
x2=(-sqrt(m)-b)/(2*a);
if (a==0)
{ if(b==0)
{printf("NOT A EQUATION"); }
else if(b!=0)
{printf("x1=%lf",c/(-b));}
}

``````else if (a!=0)
{  if(m>=0)
{if(x1>x2)
{printf("x1= %lf x2= %lf",x1,x2);}
else if(x1<=x2){  temp=x1;x1=x2;x2=temp;
printf("x1=%lf x2=%lf",x1,x2);}
else if(m<0)
{printf("无解");}
}

return 0;
``````

}
ps:求大神帮我看看一下

3个回答

rl529014   2016.02.21 16:36

rl529014   2016.02.21 16:36

mengyin521   2016.02.21 22:57

#include "stdafx.h"
#include "math.h"

int main(int argc, char* argv[])
{ double a,b,c,x1,x2,m,temp;
scanf("%lf %lf %lf",&a,&b,&c);
m=b*b-4*a*c;
x1=(sqrt(m)-b)/(2*a);
x2=(-sqrt(m)-b)/(2*a);
if (a==0)
{ if(b==0)
{printf("NOT A EQUATION"); }
else if(b!=0)
{printf("x1=%lf",c/(-b));}
}
else if (a!=0)
{ if(m>=0)
{
if(x1>x2)
{
printf("x1= %lf x2= %lf",x1,x2);
}
else if(x1<=x2)
{ temp=x1;x1=x2;x2=temp;
printf("x1=%lf x2=%lf",x1,x2);
}
else if(m<0)
{
printf("无解");
}
}
} //-----------------------------------------这里少括号 } -----------------------------------------------------------------------

return 0;
}