为了账号安全,请及时绑定邮箱和手机立即绑定

c语言中求幂的问题,求指教!

c语言中求幂的问题,求指教!

C
Forgetit00 2016-10-07 09:41:18
输入x与n,输出x的n次幂,结果保留三位小数
查看完整描述

4 回答

已采纳
?
望远

TA贡献1017条经验 获得超1032个赞

#include<stdio.h>

#include<math.h>

void main(){

         float x,y;

         float total=0;

         printf("x=");

         scanf("%f",&x);

         printf("y=");

         scanf("%f",&y);

         total=(float)pow(x,y);

        printf("%.3f的%.3f次幂为:%.3f\n",x,y,total);

}


查看完整回答
1 反对 回复 2016-10-07
?
皓韵儿

TA贡献86条经验 获得超114个赞

#include <math.h> 里面有个求幂的函数, pow(x, n) 就是求得x的n次幂, 下面是代码。有什么不会的欢迎随时询问。


#include<stdio.h>

#include<math.h>

int main(){

        double x,n;

        double sum = 0;

        printf("x=");

        scanf("%lf",&x);

        printf("n=");

        scanf("%lf",&n);

        sum=(double)pow(x,n);

        printf("%.3lf的%.3lf次幂为:%.3lf\n",x,n,sum);

        return 0;

}


查看完整回答
2 反对 回复 2016-10-07
?
递胜递负

TA贡献1条经验 获得超0个赞

求x的n次方


查看完整回答
反对 回复 2016-12-03
?
雪颲

TA贡献220条经验 获得超117个赞

累乘啊,递归调用自己

查看完整回答
反对 回复 2016-10-07
点击展开后面1
  • 4 回答
  • 0 关注
  • 1616 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信