C++计算2的5次方

来源:百度知道 编辑:UC知道 时间:2024/05/29 16:07:35
有现成的公式吗?小弟的意思是不用在具体编程算了。C++有没有关于乘方的运算符

#include <math.h>
#include <stdio.h>

void main( void )
{
double x = 2.0, y = 3.0, z;

z = pow( x, y );
printf( "%.lf to the power of %.lf is %.lf\n", x, y, z );
}

Output

2.0 的3次方是 8.0

有这样的运算公式,在头文件#include <cmath>里边
首先要头文件#include <cmath>
然后,比如你说的:2的5次方就是:pow(2,5);
也就是 x的y次方就是pow(x,y);
测试程序:

#include <cmath>
#include "iostream.h"
main()
{
int a;
a=pow(2,5);
cout<<"a的值是:"<<a;
}

不明白了,q我:172610236

有啊
#include<cmath>

pow(x,5)x的5 次方