gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 05:48:22 24 4
gpt4 key购买 nike

我目前正在阅读 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com