mwfd.net
当前位置:首页 >> 编写程序计算s=1+1/2!+1/3!+1/4!+...1/n! >>

编写程序计算s=1+1/2!+1/3!+1/4!+...1/n!

var s:real; n:longint;function jc(x:longint):longint;var i:longint;begin jc:=1; for i:=2 to x do jc:=jc*i;end;function sum:real;var i:longint;begin sum:=0; for i:=1 to n do sum:=sum+1/js(i);end;begin readln(n); s:=sum; writeln(s);end.

Private Sub Command1_Click()Dim n As Integern = 1Do While 1 / n >= 0.0001n = n + 1s = s + 1 / nLoopPrint sEnd Sub(还有就是最后一项应该是不大于0.0001吧???)

你这个肯定不对,这个是我在网抄上搜的,你看看吧 编写程序计算S=1+1+2+1+2+3+1+2+3+4+…+1+2+3+4+…+n,当S>2000时,n的最小值袭和此时的S值. 下面是C语言编zhidao程:#include int main() { int n,i,j,s=0; do { n=n+1; i=i+n; s=j+i; }while(s>2000) printf("n=%d,s=%d",n,s); }

//计算分母上的幂int N2N(int n){int i=0;int s=1;while(i{s*=n;i++;}return s;}//主函数,计算累加和int Main(){int i,n,s;s=i=0;while(i{s+=1/N2N(i);i++;}}

#includevoid main(){int s=0,a,n; cout>n; for(int i=1;i 评论0 0 0

不知道你需要用什么语言编写,给你个c的例子#include <stdio.h> int sfun( int n ) { int i,j,s; s = 0; for( i = 1; i <= n; i++ ) { for( j = 1; j <= i; j++ ) { s += j; } } return s; } void main() { int n, s; printf( "请输入n的值:\n" ); scanf( "%d", &n ); s = sfun( n ); printf( "n=%d时,s=%d\n", n, s ); }

double a=1,b=0; for (int i=1; i<=n; i++) { a = a * i; b = b + 1/a; } 最后所求结果就是b+1

CLEARSET TALK OFFs=0s1=0i=0DO WHILE s1<2 i=i+1 s=s1 s1=s1+1/i ENDDO? "s的值为",s? "项数为",i-1SET TALK ON

由于你的n是int型,则1/n是整数,程序中的1/n或(-1)/n一直是0,所以s一直都是0;将t=1/n和t=(-1)/n改为t=1/(float)n和t=-1/(float)n即可,即将n强制转换为float型,这样1/n就可以表示为小数了.希望可以帮到你!

你好!int n=1;float s=0;dos=s+1/n;n=n+1;while (1/n 评论0 0 0

相关文档
369-e.com | 9647.net | xyjl.net | tuchengsm.com | xaairways.com | 网站首页 | 网站地图
All rights reserved Powered by www.mwfd.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com