C语言乘方运算
来源:百度知道 编辑:UC知道 时间:2024/07/02 00:19:25
怎么写?
C语言的乘方运算可以利用库函数pow。
pow函数原型:double pow( double x, double y );
头文件:math.h/cmath(C++中)
功能:计算x的y次幂。
参考代码:
#include <stdio.h>
#include <math.h>
int main()
{
int a=3,b=2;
double t = pow(a,b);//计算3的平方并输出
printf("%.0lf\n",t);
return 0;
}
/*
输出:
9
*/
#include <math.h>
#include<stdio.h>
void main()
{
double a = pow(4, 7); // a等于4的7次方
}
#include <math.h>
pow(x, y) /* 计算x的y次方 */
#include<math.h>
double pow(double x,double y)
表示x的y次方