用C++编2的4次方等于多少?谢谢了

来源:百度知道 编辑:UC知道 时间:2024/06/08 18:06:03

pow(a,b)//求a的b次幂.

如果是VS2005 则
#include <iostream>
#include <math.h>
using namespace std ;

void main()
{
double a = 2 ;
double b = 4 ;
cout << pow(a, b) << endl ;
}
由于pow函数有多个重载函数, 所以你最好先指定参数的类型, 否则编译器不知道该选哪个函数来匹配.

#include "streamio.h"
#include "math.h"
void main()
{
cout<<"2*2*2*2="<<pow(2,4)<<endl;
}

pow是专用来算幂的,第一参数是底数(好像是叫这个吧),第二个参数是次数。