gpt4 book ai didi

c - C 的幂?

转载 作者:行者123 更新时间:2023-11-30 16:42:18 25 4
gpt4 key购买 nike

所以在Python中,我所要做的就是

print(3**4) 

这给了我 81

如何在 C 语言中执行此操作?我搜索了一下并说 exp()功能,但不知道如何使用它,提前感谢

最佳答案

您需要 math.h header 中的 pow(); 函数。
语法

#include <math.h>
double pow(double x, double y);
float powf(float x, float y);
long double powl(long double x, long double y);

这里 x 是底数,y 是指数。结果是x^y

用法

pow(2,4);  

result is 2^4 = 16. //this is math notation only
// In c ^ is a bitwise operator

并确保包含 math.h 以避免警告(“内置函数 'pow' 的不兼容隐式声明”)。

编译时使用-lm链接数学库。这取决于您的环境。
例如,如果您使用 Windows,则不需要这样做,但在基于 UNIX 的系统中则需要这样做。

关于c - C 的幂?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45889977/

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