c语言字符幂函数怎么编写,c语言幂函数_C ++中的幂函数

c语言幂函数

C ++幂函数 (C++ power functions)

Power functions are used to calculate the powers (like, raise to power, square root, cubic root, etc). There are following power functions which are the library functions of cmath header.

幂函数用于计算幂(例如,提高到幂,平方根,立方根等)。 有以下幂函数 ,它们是cmath标头的库函数。

pow() function pow()函数 sqrt() function sqrt()函数 cbrt() function cbrt()函数 hypot() function hypot()函数

1)pow()函数 (1) pow() function)

pow() function is a library function of cmath header ( in earlier versions), it is used to find the raise to the power, it accepts two arguments and returns the first argument to the power of the second argument.

pow()函数是cmath标头的库函数(在早期版本中为),用于查找幂的加数,它接受两个参数并将第一个参数返回为第二个参数的幂。

Syntax of pow() function:

pow()函数的语法:

pow(x, y);

2)sqrt()函数 (2) sqrt() function)

sqrt() function is a library function of cmath header ( in earlier versions), it is used to find the square root of a given number, it accepts a number and returns the square root.

sqrt()函数是cmath标头(在早期版本中为 )的库函数,用于查找给定数字的平方根,它接受数字并返回平方根。

Note: If we provide a negative value, sqrt() function returns a domain error. (-nan).

注意:如果我们提供负值,则sqrt()函数将返回域错误。 ( -nan )。

Syntax of sqrt() function:

sqrt()函数的语法:

sqrt(x);

3)cbrt()函数 (3) cbrt() function)

cbrt() function is a library function of cmath header, it is used to find the cubic root of a given number, it accepts a number and returns the cubic root.

cbrt()函数是cmath标头的库函数,用于查找给定数字的立方根 ,它接受数字并返回立方根。

Syntax of cbrt() function:

cbrt()函数的语法:

cbrt(x);

4)hypot()函数 (4) hypot() function)

hypot() function is a library function of cmath header, it is used to find the hypotenuse of the given numbers, it accepts two numbers and returns the calculated result of hypotenuse i.e. sqrt(x*x + y*y).

hypot()函数是cmath标头的库函数,用于查找给定数字的斜边,接受两个数字并返回斜边的计算结果,即sqrt(x * x + y * y) 。

Syntax of hypot() function:

hypot()函数的语法:

hypot(x, y);

C ++程序演示幂函数示例 (C++ program to demonstrate example of power functions)

// C++ program to demonstrate example of

// power functions

#include

#include

using namespace std;

// main() section

int main()

{

float x, y;

float result;

//pow() function

x = 12;

y = 4;

result = pow(x,y);

cout<

cout<

//sqrt() function

x = 2;

result = sqrt(x);

cout<

cout<

//cbrt() function

x = 2;

result = cbrt(x);

cout<

cout<

//hypot() function

x = 2;

y = 3;

result = hypot(x,y);

cout<

cout<

return 0;

}

Output

输出量

12 to the power of 4 is : 20736

square root of 2 is : 1.41421

cubic root of 2 is : 1.25992

hypotenuse is : 3.60555

翻译自: https://www.includehelp.com/cpp-tutorial/power-functions.aspx

c语言幂函数

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值