㈠ c语言中的幂函数··
extern float pow(float x, float y)
用法:#include <math.h>
功能:计算x的y次幂。
说明:x应大于零,返回幂指数的结果。
举例:
// pow.c
#include <stdlib.h>
#include <math.h>
#include <conio.h>
void main()
{
printf("4^5=%f",pow(4.,5.));
getchar();
}
相关函数:pow10
㈡ c语言中的幂函数pow用法 谁能帮我用pow编个程序求3.5的1/4次方
#include "stdio.h"
#include "math.h"
void main()
{
printf("%.5f\n", pow(3.5, 0.25)); //计算3.5的0.25次方,保留小数点后5位
}
㈢ C语言幂函数计算代码
#include<stdio.h>
double
m(int
x,int
n
)
{
double
p=1;
int
i=1;
for(i=1;i<=n;i++)
p=p*x;
return
p;
}
int
main()
{
int
x,y;
scanf("%d
%d",&x,&y);
printf("%.lf\n",m(x,y));
return
0;
}
不是对的吗?还有C语言有库函数pow就是专门求幂运算的。
㈣ 在c语言里怎么编写1/2次幂
c语言有自带的代码:
pow(x,y)
其中x为底数,y为指数,
pow(x,y)=x^y,即x的y次方
例如:pow(4,1/2)=2
注意的是:其中pow函数在头文件math.h中,所以调用该函数的时候,必须将math.h加进来。
㈤ c语言幂函数
可以网络一下pow函数,返回值是double型的,所以printf需要写成:
printf("%lf\n",pwo(y,3));
㈥ c语言中编写x的n次方怎么弄啊
C语言中计算x的n次方可以用库函数pow来实现。函数原型:double pow(double x, double n)。
具体的代码如下:
#include <stdio.h>
#include <math.h>
int main( )
{
printf("%f",pow(x,n));
return 0;
}
注:使用pow函数时,需要将头文件#include<math.h>包含进源文件中。
(6)用c语言怎么编写幂函数扩展阅读:
使用其他的方法得到x的n次方:
#include<stdio.h>
double power(double x,int n);
main( )
{
double x;
int n;
printf("Input x,n:");
scanf("%lf,%d",&x,&n);
printf("%.2lf",power(x,n));
}
double power(double x,int n)
{
double a=1.0;
int i;
for(i=1;i<=n;i++)
a*=x;
return a;
}
㈦ C语言计算幂函数怎么算
#include
<stdio.h>
int
main(void)
{
int
x,y=1,z;
printf("Enter
x:");
scanf("%d",&x);
for(z=1;z<=x;z++)
{
y=y*x;
}
printf("y=%d",y);
return
0;
}
或
#include
<stdio.h>
#include
<math.h>
int
main(void)
{
int
x,y;
printf("Enter
x:");
scanf("%d",&x);
y=pow(x,x);
printf("y=%d",y);
return
0;
}