错在哪里呢?
#include<stdio.h>#include<math.h>
int main(void)
{
int a = 1;
int b = 2;
int c = 3;
float delta;
float x1;
float x2;
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",x1);
}
else
{
printf("该一元二次方程无解");
}
return 0;
}
--------------------Configuration: 1 - Win32 Debug--------------------
Compiling...
1.cpp
E:\练习\1\1.cpp(12) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
E:\练习\1\1.cpp(16) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
E:\练习\1\1.cpp(17) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
E:\练习\1\1.cpp(22) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
E:\练习\1\1.cpp(24) : error C2018: unknown character '0xa3'
E:\练习\1\1.cpp(24) : error C2018: unknown character '0xac'
E:\练习\1\1.cpp(24) : error C2146: syntax error : missing ')' before identifier 'x1'
E:\练习\1\1.cpp(24) : error C2059: syntax error : ')'
执行 cl.exe 时出错.
1.obj - 1 error(s), 0 warning(s)
[ 本帖最后由 雪燃 于 2011-3-27 11:49 编辑 ]