c+pow函数的头⽂件_pow()函数以及C++中的⽰例
c+pow函数的头⽂件
C ++ pow()函数 (C++ pow() function)
cmath header (<math.h> in earlier versions), it is used to find the raise to the power, pow() function is a library function of cmath
pow() function
it accepts two arguments and returns the first argument to the power of the second argument.
cmath标头的库函数(在早期版本中为<math.h>),⽤于查幂的加数,它接受两个参数并将第⼀个参数返回为第⼆个参数的pow()函数是cmath
pow()函数
幂。
Syntax of pow() function:
pow()函数的语法:
pow(x, y);
Parameter(s): x, y – are the numbers to calculate x^y.
Parameter(s):
参数: x,y –是⽤于计算x ^ y的数字。
参数:
Return value: double – it returns double value that is calculate result of x to the power of y.
Return value:
返回值:
返回值: double-返回double值,它是x的计算结果乘以 y的幂。
Example:
例:
Input:
float x = 2;value函数什么意思
float y = 3;
Function call:
pow(x,y);
Output:
8
C ++代码演⽰pow()函数的⽰例 (C++ code to demonstrate the example of pow() function)
// C++ code to demonstrate the example of
// pow() function
#include <iostream>
#include <cmath>
using namespace std;
// main code section
int main()
{
float x;
float y;
//input the values
cout<<"Enter the value of x: ";
cin>>x;
cout<<"Enter the value of y: ";
cin>>y;
// calculate the power
float result = pow(x,y);
cout<<x<<" to the power of "<<y<<" is = "<<result;    cout<<endl;
return 0;
}
Output
输出量
First run:
Enter the value of x: 10
Enter the value of y: 5
10 to the power of 5 is = 100000
Second run:
Enter the value of x: 10.23
Enter the value of y: 1.5
10.23 to the power of 1.5 is = 32.72
Third run:
Enter the value of x: 10
Enter the value of y: 0
10 to the power of 0 is = 1
Fourth run:
Enter the value of x: 0
Enter the value of y: 1.5
0 to the power of 1.5 is = 0
c+pow函数的头⽂件