c语言计算e的x次方的值

首先,我们需要知道公式
ex=1+x/1!+x2/2!+x3/3!+……

我们要用到函数pow(x,y),其作用是求xy,这个函数需要头文件math.h,下面给出源码。

#include<stdio.h>
#include<math.h>
int main()
{
 double e,d,i,l=1.0,x;
 scanf("%lf",&x);
 for(i=1;i<100;i++)
 {
  l*=i;
  d=pow(x,i);
  e+=d/l;
 }
 printf("%lf",e+1);
 return 0;
}

希望对大家有所帮助 >_<

发布了23 篇原创文章 · 获赞 3 · 访问量 502

猜你喜欢

转载自blog.csdn.net/qq_45861670/article/details/104047975