C语言编写程序运行时程序停止工作 老师布置的作业 电路运算

#include<stdio.h>

int main()
{
float R1,R2,R3,X1,X2,X3,U;
float a,b,c,d,e,f;
printf("请输入电压:");
scanf("%f",U);
printf("输入电阻R1,R2,R3:");
scanf("%f,%f,%f",R1,R2,R3);
printf("输入电感X1,X2,X3:");
scanf("%f,%f,%f",X1,X2,X3);
a = R2+R3;
b = X2+X3;
c = R1*R2 + R2*R3 + R1*R3 - X1*X2 - X1*X3 - X2*X3;
d = X1*R2 + X2*R3 + X1*R3 + R1*X2 + R2*X3 + R1*X3;
if(c*c == d*d)
printf("无解");
else
{
e = U*(a*c+b*d)/(c*c-d*d);
f = U*(b*c-a*d)/(c*c-d*d);
printf("\n所求电流I为:%f+j%f\n",e,f);
}
return 0;
}

scanf("%f",U);等等
改为
scanf("%f",&U);图片说明

 scanf("%f,%f,%f",R1,R2,R3);

应为:

 scanf("%f,%f,%f",&R1,&R2,&R3);

其余输入也是如此,需要在变量名加取地址操作符&。
另外请注意,在终端输入时格式应与scanf中格式字符串的写法保持一致。
题目中的输入应该类似:

 3.5,10.2,8.0    //注意用逗号分隔,与scanf中格式字符串的写法保持一致

如果对您有帮助,请采纳答案好吗,谢谢!