rjps.net
当前位置:首页 >> C语言泰勒级数计算Ex >>

C语言泰勒级数计算Ex

#include<stdio.h>#include<math.h> int main() { double add(double x, double n); double x, n,sum; scanf("%lf %lf", &x, &n); if(n<0||x<0) { printf("error"); return 0; } else { sum = add(x, n); printf("%.6lf", sum); } return 0; } double add(double x,

#include <stdio.h> int main(void) { int n; while(scanf("%d",&n)) { printf("Input n\n"); double ans=1; int i,accu=1; for(i=1;i<=n;i++) { accu*=i; ans+=1/(double)accu; } printf("e = %f\n",ans); } return 0; }

#include main() { float i=1,e=0; e+=1/i; do { i=i*(i+1) e+=1/i; }while((1/i)printf("%f",e) }

#include <stdio.h>int main() {double x,t=1,e=1; int i; scanf("%lf",&x); for(i=1;i<20;i++){t*=x/i; e+=t;}printf("%.10lf\n",e);return 0;}

另一个函数实现xn,是x*n的意思还是x的n次幂的意思,即x^n,还请描述清楚哦.#include <stdio.h>//求n!的值 int factorial(int n) { if(n == 1) return 1; else return n*factorial(n-1); }//求x的n次幂 int nth_power(int x, int n) { int i; int result = x; if(x == 0)

#include int main() { int i; float a=1, sum=1; for(i=1; a>=1E-5; i++){ a/=i; sum+=a; } printf("e=%f n=%d\n", sum, i+1); return 0; }fabs都用不着,全是正的

#include "stdio.h" void main() { float e=1.0,t=1.0; int n=1; while(1/t>(1e-6)) //(1/n!,你书写有错,i应是1 { t=t*n; //得到 n!e=e+1/t; //累加(1/n!),即计算此行前 e = 1+(1/1!)+(1/2!)+.+(1/(n-1)!)再加上(1/n!) n++; //n : 2 3 4 } printf("e=%8.6f\n",e); }

12345678910111213141516 #include<stdio.h> intmain() { floati=1,e=0; intp = 1; e+=1/i; do { i*=(p++); e+=1/i; }while((1/i)>1e-9); printf("%f",e); FILE* fp = fopen("result.txt","w"); fprintf(fp,"%f",e); fclose(fp); } 会输出到result.txt磁盘文件中

不需要用pow的double expx(double x){ double ret = 1; double xx; int n = 2; for (xx = x; xx >= 0.00000001; xx *= x/n++) { ret += xx; } return ret;}

#include<stdio.h>int main(){float i,e=1.0,t=1.0; for(i=1;t>=1.0e-6;i+=1) {t/=i; e+=t; } printf("e=%f\n",e); getch();return 0;}

qwfc.net | jjdp.net | nwlf.net | bnds.net | ddng.net | 网站首页 | 网站地图
All rights reserved Powered by www.rjps.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com