mdsk.net
当前位置:首页 >> 编写程序,根据近似公式E≈1+1/(1!)+1/(2!)+1/(3!)+…+1/(n!)计算E的近似... >>

编写程序,根据近似公式E≈1+1/(1!)+1/(2!)+1/(3!)+…+1/(n!)计算E的近似...

clear s=0 n=1 do while .t. m=1 for i=1 to n m=m*i endfor r=1/m s=s+r if r exit endif n=n+1 enddo?"e=1+1/1!+1/2!+1/3!+…+1/n!=",s

e=1+1/1!+1/2!+1/3!+.C代码:#includevoid main(){double e=1;double jc=1;//求阶乘,并存入jc中int i=1;while(1/jc>=1e-6){e=e+1/jc;i++;jc=jc*i;}printf("e=%f\n",e);}还有不懂可以HI我,只要我力所能及.

a)中用一个循环就行了为啥要用两个捏?#include "stdio.h"int main(){ int i,N=1; double EE=0; for(i=1;(1.0/N)>1e-6;i++){ N*=i; EE+=1.0/N; } printf("e的值为:%f",EE); return 0;}我又改了下使用两个循环:#

#include <math.h> main() { int n,i,b; long a=1; double e,x; printf("Input n:"); scanf("%d",&n); for(i=1;i<=n;i++) { a*=i; e+=1.0/a; } printf("e=%lf",e); x=e-(int)e; printf(" input bit b(1~14):");/*这边给您输出最多14位的小数*/ scanf("%d",&b);

#include "stdio.h" float fun(int n){ float t=1.0; int i; for(i=1;it*=i;} return t;} void main(){ float e=1.0; int n=1; while(1/fun(n)>=10e-6){ e+=1.0/fun(n); n++;} printf("%f",e); }

在Excel里面用VB编个小小的程序就可实现 程序代码如下:Sub valueE() e = 1 Do n = n + 1 k = 1 For i = 1 To n m = k * i k = m Next e = e + 1 / m Loop Until 1 / m < 10 ^ (-6) Cells(1, 1) = "n" Cells(1, 2) = "valueE" Cells(2, 1) = n + 1 Cells(2, 2) = e End Sub 实验结果如下:

1.//---------------------------------------------------------------------------#include #define N 50int main(int argc, char* argv[]){ double e=1,t=1; int t1; for (t1=2;t1const double eps=1e-13;int main(int argc, char* argv[]){ double e=0,t,t1; t=t1=1; while (t-(1e-4)>eps) { e+=

1.k=1 t=1 e=02. t=t*(1/k) 3.e=e+t4. k=k+15. if t>10^(-6) goto 26.print e7,end

这程序不难的..自己看c里的循环语句可以解决的把式子中分母设为n 循环加1,乘以上次的值赋给式子,再,加起来赋给和,循环推出条件判断(可设为没个式子的值小于某个值时推出循环 ,你试着有while做吧

(1)#include<stdio.h>int main(){ double item=1,sum=1,n; for(n=1;n<=20;n++) { item*=1.0/n; sum+=item; } printf("The sum is %lf\n",sum); return 0;}(2)#include<stdio.h>#include<math.h>int main(){ double item=1,sum=1,n=1; do { item*=1.0/n; sum+=

相关文档
rxcr.net | lpfk.net | fnhp.net | 3859.net | hyfm.net | 网站首页 | 网站地图
All rights reserved Powered by www.mdsk.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com