c - 在 C 中使用 pow() 有问题

标签 c exponent

我目前正在阅读 Stephen Kochan 的“C 语言编程(第 3 版)”的在线版本。其中一项事件涉及评估方程式,

Write a program that evaluates the following expression and displays the results (remember to use exponential format to display the result): (3.31 x 10-8 x 2.01 x 10-7) / (7.16 x 10-6 + 2.01 x 10-8)

当我尝试这样做时,输出始终为 0.0000。这是我的代码。

#include <stdio.h>
int main (void) {
float result;
    result = (3.31 * pow(10,-8) * 2.01 * pow(10,-7)) / (7.16 * pow(10,-6) + 2.01 * pow(10, -8));
    printf ("%f", result);
    return 0;
}

如果我做错了什么,请指出。如果您有任何提示,请说出来。

最佳答案

你必须#include <math.h>

此外,更改为:

printf ("%e\n", result);

你应该也有

double result;

因为pow()返回 double .

关于c - 在 C 中使用 pow() 有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52955680/

相关文章:

c - 如何在 C 中获取十六进制日期和时间

cryptography - 当指数超过 10 个字节时,Java Card setExponent() 方法失败

javascript - 计算数字乘数后缀的更简单方法

根据导数或指数级别对 Mathematica 中的公式进行排序

c++ - C++ 或 C 中的打包值

c - 在文本文件中搜索字符串并解析该行(Linux、C)

在 C 程序中计算最大 int 值 (1 << 31) - 1

c - 自动将一个套接字转发到另一个套接字

python - 为什么 np.array([1e5])**2 与 Python 中的 np.array([100000])**2 不同?

java - 递归指数法