要在C中的权力? [英] To the power of in C?

查看:106
本文介绍了要在C中的权力?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此​​,在蟒蛇,我所要做的就是

So in python, all I have to do is

print(3**4) 

这给了我81

我怎么做这在C?我搜索了一下,说, EXP()的功能,但不知道如何使用它,在此先感谢

How do I do this in C? I searched a bit and say the exp() function, but have no clue how to use it, thanks in advance

推荐答案

您需要 POW(); 从功能文件math.h 头。结果
语法

You need pow(); function from math.h header.
syntax

   #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 ^是

Here x is base and y is exponent. result is x^y.

使用

pow(2,4);  

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

和确保包含文件math.h 来避免警告(的内置函数'战俘')。

And make sure you include math.h to avoid warning ("incompatible implicit declaration of built in function 'pow' ").

通过链接数学库 -lm 在编译时。这取决于你的环境。结果
例如,如果你用它这样做不是必需的Windows,但它是在基于UNIX的系统。

Link math library by using -lm while compiling. This is dependent on Your environment.
For example if you use Windows it's not required to do so, but it is in UNIX based systems.

这篇关于要在C中的权力?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆