C++中pow(x,y)函数怎么用?最好给举个例子…

如题所述

系统只提供下面参数类型的pow函数……
C/C++ code
double pow(double, double)long double std::pow(long double, int) float std::pow(float, int)double std::pow(double, int)long double std::pow(long double, long double)float std::pow(float, float)

例子:
int main(int argc, char *argv[]){ int x=2.0,y=3,z; z=pow(x,y); return z;}
温馨提示:内容为网友见解,仅供参考
第1个回答  2013-04-26
求x的y次幂如果你要求2的4次幂,就写 pow(2,4),它就算出来了.
第2个回答  2017-06-26
//假设要计算2的10次方
#include <stdio.h>
#include <math.h>
void main()
{
int data = pow(2,10);
printf("%d",data);
}

第3个回答  2017-07-19

Example:

/* pow example */
#include <stdio.h>      /* printf */
#include <math.h>       /* pow */

int main ()
{
  printf ("7 ^ 3 = %f\n", pow (7.0, 3.0) );
  printf ("4.73 ^ 12 = %f\n", pow (4.73, 12.0) );
  printf ("32.01 ^ 1.54 = %f\n", pow (32.01, 1.54) );
  return 0;
}

Output:


7 ^ 3 = 343.000000
4.73 ^ 12 = 125410439.217423
32.01 ^ 1.54 = 208.036691

参考链接:http://www.cplusplus.com/reference/cmath/pow/

本回答被网友采纳
相似回答