c语言 帮忙写下这个公式

来源:百度知道 编辑:UC知道 时间:2024/06/24 11:25:42
e^x = 1 + x/1! + x^2/2! + x^3/3! + ...+ x^n/n!
^是乘方的意思
例如e^x意思是:e的x次方。
对不起,这个公式里x和n是要输入的值
这是要输出的结果:
enter value of x:2
enter number of terms(n):18

the approximated value of e^x:7.389056098885
the value of e^x using c library function:7.389056098931

the absolute difference between the two value:
0.0000000000046

拜托再帮我一次,等我积分够了,就给你追加。
我现在就在给别人答题呢。

#include "stdio.h"
#include<stdlib.h>
#include "math.h"

void main(){
int n;
float x,t=1,sum=1;
printf("enter value of x:");
scanf("%f",&x);
printf("enter number of terms(n):");
scanf("%d",&n);
for (int i=1;i<=n;i++){
t/=i;
t*=x;
sum+=t;
}
printf("the approximated value of e^x:%16.12f\n",sum);
printf("the value of e^x using c library function:%16.12f\n",exp(x));
printf("the absolute difference between the two value: %16.16f\n",abs(sum-exp(x)));
}

#include "stdio.h"
#include "math.h"
main()
{
int n,i,z,data=1;
double x,sum=1;
int e= /* 忘了e是多少了,自己填一下吧*/
printf("enter value of x:");
scanf("%d",x);
printf("enter number of terms(n):");
scanf("%d",&n);
for(i=1;i&