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
热门推荐
10 祝女儿简短祝福语大全
11 大学新年祝福语简短创意
12 元旦适合的祝福语简短
13 朋友出远门祝福语简短
14 初六简短的祝福语
15 祝男孩生日祝福语简短
16 同事调离的祝福语简短
17 拜年红包的祝福语简短
18 妈妈生日祝福语简短励志