初学C语言出现执行 cl.exe 时出错

2024-11-16 22:35:04
推荐回答(5个)
回答1:

我给你改了如下,你自己看吧:

# 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;
}

你的代码中有部分错误,你仔细看看,不懂的话,再问吧。

回答2:

错误信息是什么?
完全没有格式。。。
# 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;
}
试试上面的代码

回答3:

#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;}

回答4:

printf语句后面都加上分号

回答5:

一开始看你的大括号就用错了 还是慢慢来