#include
main()
{
float R1,R2,U,I1,I2;
printf("Input three numbers R1,R2,U:");
scanf("%lf,%lf,%lf",&R1,&R2,&U);
I1=U/(R1+R2);
I2=U*((R1*R2)/(R1+R2));
printf("I1=%0.2lf\n,I2=%0.2lf\n,I1,I2");
getch();
}
float R1,R2,U,I1,I2;
->
double R1,R2,U,I1,I2;
该回答引用GPTᴼᴾᴱᴺᴬᴵ
这段代码存在两个问题:
1.变量类型错误:应该使用 %f 格式化字符串来读取 float 类型的输入值,而不是 %lf,该格式化字符串用于读取 double 类型的输入值。
2.输出语句错误:在输出 I1 和 I2 的值时,应该去掉双引号并将变量名放在 %f 格式化字符串中,如下所示:
printf("I1=%0.2f\n,I2=%0.2f\n",I1,I2);
修正后的代码如下:
#include<stdio.h>
int main()
{
float R1,R2,U,I1,I2;
printf("Input three numbers R1,R2,U:");
scanf("%f,%f,%f",&R1,&R2,&U);
I1=U/(R1+R2);
I2=U*((R1*R2)/(R1+R2));
printf("I1=%0.2f\n,I2=%0.2f\n",I1,I2);
getch();
return 0;
}
%lf 是double类型,你定义的是float 改成%f或者float换成double
float要用%f输入才行,不可以使用%lf!!!
要么类型是float,输入用%f;要么类型用double,输入用%lf,必须对应