这个是我编译器里面的报错
总共三个错误
float 声明的时候应该用 %f 好像
第八行和第十三行最后的分号是中文分号
if 语句不需要 return,return 用在 void 里
改过的代码没有具体调试
Untitled.cpp:6:17: warning: format specifies type 'int *' but the argument has type 'float *' [-Wformat]
scanf("%d%d%d",&a,&b,&c);
~~
^~
%f
Untitled.cpp:6:20: warning: format specifies type 'int *' but the argument has type 'float *' [-Wformat]
scanf("%d%d%d",&a,&b,&c);
~~
^~
%f
Untitled.cpp:6:23: warning: format specifies type 'int *' but the argument has type 'float *' [-Wformat]
scanf("%d%d%d",&a,&b,&c);
~~
^~
%f
Untitled.cpp:8:45: error: non-ASCII characters are not allowed outside of literals and identifiers
printf("二元一次方程的a不能为0");
^~
Untitled.cpp:8:45: error: expected ';' after expression
printf("二元一次方程的a不能为0");
^
;
Untitled.cpp:9:3: error: non-void function 'main' should return a value [-Wreturn-type]
return;
^
Untitled.cpp:13:40: error: non-ASCII characters are not allowed outside of literals and identifiers
printf("该二元一次方程无解");
^~
Untitled.cpp:13:40: error: expected ';' after expression
printf("该二元一次方程无解");
^
;
Untitled.cpp:14:3: error: non-void function 'main' should return a value [-Wreturn-type]
return;
^
3 warnings and 6 errors generated.
程序代码:
#include <stdio.h>
#include <math.h>
int main(){
float a,b,c,disc,x1,x2,p,q;
printf("请输入二元一次方程的三个系数:");
scanf("%f%f%f",&a,&b,&c);
if(a==0){
printf("二元一次方程的a不能为0");
}
disc=b*b-4*a*c;
if(disc<0){
printf("该二元一次方程无解");
}
p=-b/(2*a);
q=sqrt(disc)/(2*a);
x1=p+q;
x2=p-q;
printf("x1=%f\nx2=%f",x1,x2);
}
[此贴子已经被作者于2017-12-5 14:25编辑过]