我给你改了如下,你自己看吧:
# include
# include
int main(void)
{
int a = 1;
int b = 2;
int c = 3;
double delta;
double x1,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 + sqrt(delta))/(2*a);
x2 = x1 ;
printf("x1 = %f, x2 = %f\n", x1); }
else { printf("无解") ;}
return 0;
}
你的代码中有部分错误,你仔细看看,不懂的话,再问吧。
错误信息是什么?
完全没有格式。。。
# include
# include
int main(void){
int a = 1;
int b = 2;
int c = 3;
double delta;
double x1,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 {
x1 = (-b + sqrt(delta))/(2*a);
x2 = x1;
printf("x1 = %f, x2 = %f\n", x1);
}
else {
printf("无解");
}
return 0;
}
试试上面的代码
#include
#include
int main()(void) {
int a=1,int b=2,int c=3;
double delta;
double x1,x2;
delta=b*b-4*a*c;
if(delta>0) {x1=(-b+sqrt(delta)/(2*a)*2=(-b-sqrt(delta)/(2*a)
printf("x1=%f,x2=%f\n",x1,x2}
else if(x1=(-b+sqrt(delta))/(2*a)*2=x1
printf("x1=%f,x2=%f\n",x1}
else printf("无解")}
return 0;}
printf语句后面都加上分号
一开始看你的大括号就用错了 还是慢慢来