【发布时间】:2016-07-06 20:08:04
【问题描述】:
这是C程序
#include <stdio.h>
#include <stdlib.h>
int main (void){
double voltage, resistance;
printf("Enter your Voltage: ");
scanf("%f", &voltage);
printf("Enter your Resistance: ");
scanf("%f", &resistance);
double amps = voltage / resistance;
printf("With voltage %f and Ohm %fohms, amps is equal to %f \n", voltage, resistance, amps);
return 0;
}
为什么电压和电阻变量的返回值为 0.00?
【问题讨论】:
-
嘿,谢谢,你能解释一下添加“l”的作用吗?
-
你可能想在
scanf()上进行RTFM:iso-9899.info/n1570.html#6.2.5p28 -
你的编译器应该警告格式说明符和传递的参数类型不匹配。如果不增加其警告级别。认真对待警告。
-
OT:您的结果字符串缺少电压和电流单位,以及输入提示。电阻的单位不是“ohms”而是“Ohm”,简称Ω。