C语言,帮看下程序有什么问题
/*课上作业*/
#include<stdio.h>
#include<math.h>
main()
{
float a,b,c,d,x1,x2;
a=3.2;
b=2.1;
c=-8.4;
d=b*b-4*a*c;
x1=(-b+sqrt(p))/(2*a);
x2=(-b-sqrt(p))/(2*a);
printf("x1=%f,x2=%f",x1,x2);
return 0;
}
错在哪里啊
--------------------Configuration: q - Win32 Debug--------------------
Compiling...
q1.c
D:\VC\VC\Microsoft Visual Studio\MyProjects\q\q1.c(7) : warning C4305: '=' : truncation from 'const double ' to 'float '
D:\VC\VC\Microsoft Visual Studio\MyProjects\q\q1.c(8) : warning C4305: '=' : truncation from 'const double ' to 'float '
D:\VC\VC\Microsoft Visual Studio\MyProjects\q\q1.c(9) : warning C4305: '=' : truncation from 'const double ' to 'float '
D:\VC\VC\Microsoft Visual Studio\MyProjects\q\q1.c(11) : error C2065: 'p' : undeclared identifier
D:\VC\VC\Microsoft Visual Studio\MyProjects\q\q1.c(11) : warning C4244: '=' : conversion from 'double ' to 'float ', possible loss of data
D:\VC\VC\Microsoft Visual Studio\MyProjects\q\q1.c(12) : warning C4244: '=' : conversion from 'double ' to 'float ', possible loss of data
Error executing cl.exe.
q1.obj - 1 error(s), 5 warning(s)
[解决办法]
D:\VC\VC\Microsoft Visual Studio\MyProjects\q\q1.c(11) : error C2065: 'p' : undeclared identifier
已经明显指出 在11行中 p 没有定义. (英文还是要一点的,否则使用中文版吧).
[解决办法]
p没有定义,main前面没有写返回类型。
[解决办法]
首先要从上到下看带有"error"的行
D:\VC\VC\Microsoft Visual Studio\MyProjects\q\q1.c(11) : error C2065: 'p' : undeclared identifier
一般都会提示错误原因,不行就在前面几行找一般都能解决,要不就想一想最近改了什么让它编译不过的
[解决办法]
变量p没有声明
a=3.2f;
b=2.1f;
c=-8.4f;
[解决办法]
d,x1,x2
这三个变量可以尝试定义为double类型!
[解决办法]
p没有定义。在前边定义就可以了。。
[解决办法]
总感觉这要求也太高了吧啊。。。。