【发布时间】:2013-10-05 10:59:41
【问题描述】:
我正在尝试制作欧姆定律程序。 V = 红外。
#include <stdio.h>
int main(int argc, const char * argv[]) {
int V,I,R;
printf("please enter the value of the current if the value is not known make I=0 ");
scanf("%d", &I);
printf("please entre the value of the resistance if the value is not known make R=0");
scanf("%d", &R);
printf("please enter the value of the voltage, if unknown make V=0");
scanf("%d", &V);
if (V == 0)
V = I*R;
{
printf(" V = %d",V);
}
else if (I==0)
I = V/R;
{
printf("I = %d ",I);
}
else
R = V/I;
{
printf("R= %d",R);
}
return 0;
}
我是初学者,我怎样才能改进我的代码,让它工作? 非常感谢您的帮助。
【问题讨论】:
-
欢迎来到stackoverflow。为了帮助您,我们需要知道您的实际问题是什么。您希望该程序做什么以及它会做什么?
-
请阅读C tutorial。
-
这个问题似乎离题了,因为它太本地化了。
-
您使用的是整数。如果将整数 4 除以整数 5,则得到零。
-
并在
if和else子句的完整主体周围正确放置{}括号。
标签: c if-statement floating-point scanf