在C语言中进行次方运算的方法:
一:
利用循环进行幂运算:
#include <stdio.h>
int main()
{
int i,k = 2;
for(i = 1;i < 3;i++)
{
k *= 2;
}
printf("%d",k);
return 0;
}
上述代码可以实现k的3次方运算。
二:
利用math.h中的pow()函数进行:
函数定义如下:
double pow(double x,double y)
可以实现x的y次幂(返回值)
example:
#include <stdio.h>
#include <math.h>
int main()
{
printf("%f",pow(2,3));
return 0;
}

2623

被折叠的 条评论
为什么被折叠?



