C语言pow函数

来源:百度知道 编辑:UC知道 时间:2024/06/17 14:34:28
#include<stdio.h>
#include<math.h>
#include "stdlib.h"
void f(long n)
{printf("%f\t", pow(n,3));
printf("%lf\t", pow(n,3));
printf("%ld\t", (long)pow(n,3));
printf("结果是:%I64d\t",(long long int )pow(n,3));
printf("%d\n", (int)pow(n,3));
}
main()
{long i=5;
printf("%f\t", pow(5,3));
printf("%lf\t", pow(5,3));
printf("%ld\t", (long)pow(5,3));
printf("结果是:%I64d\t",(long long int )pow(5,3));
printf("%d\n", (int)pow(5,3));
system("pause");

printf("%f\t", pow(i,3));
printf("%lf\t", pow(i,3));
printf("%ld\t", (long)pow((int)i,3));
printf("结果是:%I64d\t",(long long int )pow(i,3));
printf("%d\n", (int)pow(i,3));
system("pause");

原型:extern float pow(float x, float y);

用法:#include <math.h>

功能:计算x的y次幂。

说明:x应大于零,返回幂指数的结果。

举例:

// pow.c

#include <syslib.h>

#include <math.h>

main()

{

clrscr(); // clear screen

textmode(0x00); // 6 lines per LCD screen

printf("4^5=%f",pow(4.,5.));

getchar();

return 0;

}

1,要加入头文件 math.h
2,pow(x,y);//其作用是计算x的y次方。x、y及函数值都是double型
例:
我要计算2的5次方
源代码如下:
#include"stdio.h"
#include"math.h"
main()
{
long total;
int x = 2, y = 5;
total = pow(x,y); /*调用pow函数*/
printf("%ld",total);
getch();
}

原型:extern float pow(float x, float y);

用法:#include <math.h>

功能:计算x的y次幂。

说明:x应大于零,返回幂指数的结果。

举例: