【发布时间】:2019-06-26 14:52:41
【问题描述】:
这是我为我的学校项目编写的代码 我的问题是为什么 printf 不显示它作为 inf 出现的浮点值(我相信它是无穷大?)我知道我以前的值都是 int 的,如果我为什么将浮点数放入() 无论如何,感谢您的帮助
欢呼声
#include <stdio.h>
#include <conio.h>
int main()
{
int c1, c2, c3, parallelCap;
float seriesCap;
printf("please enter the value of the first resistor:");
scanf(" %d", &c1);
printf("please enter the value of the second rstr:");
scanf(" %d", &c2);
printf("please enter the value of the third resistor:");
scanf(" %d", &c3);
parallelCap = c1 + c2 + c3;
seriesCap = (float)1/(1/c1 + 1/c2 + 1/c3);
printf("the parallel capacitance is: %d the series
capacitance is: %f/n ", parallelCap, seriesCap);
getch();
return 0;
}
【问题讨论】:
-
1/c1 + 1/c2 + 1/c3中的所有除法都是使用整数运算完成的,所以它们都是0。 -
改成
1.0/c1 + 1.0/c2 + 1.0/c3
标签: c