会C语言 Vc6++的 帮我看看这个程序 哪里出错了 谢谢了额。

2024-11-26 14:23:03
推荐回答(3个)
回答1:

# include
# include
int main ()
{ int a = 1;
int b = 2;
int c = 3;
float delta;
float x1;
float x2;
delta=(float)(b*b-4*a*c);//强制类型转换
if ( delta > 0)
{
x1 =(float) (-b + sqrt ( delta ) ) / ( 2 * a );//强制类型转换
x2 = (float)(-b - sqrt ( delta ) ) / ( 2 * a );//强制类型转换
printf ("该方程有两个解, x1 = %f, x2 = %f\n",x1,x2);
}
else
if ( delta ==0 )
{
x1 =(float)( - b ) / ( 2 * a );//强制类型转换
x2 = x1 ;
printf ("该方程有两个相同的解, x1 = x2 = %f\n", x1, x2 );
}
else
printf ("该方程无解\n");
return 0;
}
这是我改过的,有几个地方涉及到强制类型转换(注释的地方),其他的地方细心点,比如else拼成elso,这样的错误都要避免,以后细心点就行了。

回答2:

# include
# include

int main (void)
{

int a = 1;

int b = 2;

int c = 3;

float x1;

float x2;

float delta = b*b - 4*a*c;

if ( delta > 0)
{

x1 = (-b + sqrt ( delta ) ) / ( 2 * a );
x2 = (-b - sqrt ( delta ) ) / ( 2 * a );

printf ("该方程有两个解, x1 = %f, x2 = %f\n",x1,x2);

}

else if ( delta ==0 )
{
x1 = ( - b ) / ( 2 * a );

x2 = x1 ;

printf ("该方程有两个相同的解, x1 = x2 = %f\n", x1);
}
else
{
printf ("该方程无解\n");

}

return 0;
}

回答3:

else拼错了吧