x的n次方用c++程序编程怎么写

x的n次方用c++程序编程怎么写,第1张

#include<iostream>

using namespace std

void main() { int x,y,n,i

  cin>>x>>n

  y=1 for ( i=0i<ni++ ) y*=x

  cout<<y<<endl

}

#include<stdio.h>

#include<math.h>

int main()

{

    double x,res=0

    int n,m,mfact = 1

    printf("请输入x和n的值,用空格间隔:")

    scanf("%lf %d",&x,&n)

    

    for(m=1m<=n++m)

    {

        mfact *= m

        res += pow(x,m)/mfact  

    }

    printf("结果为res=%lf\n",res+1)// 公式有错误,m应该从0开始即少了个1

    return 0

}

以上。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/11033569.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-13
下一篇2023-05-13

发表评论

登录后才能评论

评论列表(0条)

    保存