㈠ 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;
}