pow()函数以及C ++中的示例
C++pow()函数
pow()函数是cmath标头(在早期版本中为<math.h>)的库函数,用于查找幂的加数,它接受两个参数并将第一个参数返回为第二个参数的幂。
pow()函数语法:
pow(x, y);
参数:x,y–是计算x^y的数字。
返回值:double-返回double值,它是x的计算结果乘以y的幂。
示例
Input:
float x = 2;
float y = 3;
Function call:
pow(x,y);
Output:
8C++代码演示pow()函数示例
//示例
//pow()功能
#include <iostream>
#include <cmath>
using namespace std;
//主代码部分
int main(){
float x;
float y;
//输入值
cout<<"Enter the value of x: ";
cin>>x;
cout<<"Enter the value of y: ";
cin>>y;
//计算幂
float result = pow(x,y);
cout<<x<<" to the power of "<<y<<" is = "<<result;
cout<<endl;
return 0;
}输出结果
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
热门推荐
1 带狗狗训练
4 听力训练狗狗
6 怎训练狗狗
7 腹肌训练狗狗
8 网球训练狗狗
9 记叙文训练狗狗
10 狗狗太凶怎么训练
11 核心力量训练狗狗
12 狗狗乱叫怎么训练
13 发音训练狗狗
14 怎么训练狗狗叼东西给主人
15 荆州训练狗狗
16 篮球训练狗狗
17 做训练狗狗
18 训练狗狗坐姿