www.5213.net > 关于C语言的题“求S=1/1!+1/2!+1/3!+…+1/N!”我知道算法但是我的结果最后一位与标...

关于C语言的题“求S=1/1!+1/2!+1/3!+…+1/N!”我知道算法但是我的结果最后一位与标...

long long int nn,ii,zz; double sum =0,kk; nn=ii=1; do { kk=(double)1/ii; sum+=kk; nn++; ii*=nn; } while ( kk>= 1e-17 ); printf("\nS=1/1!+1/2!

public class JC { public static void main(String[] args) { System.out.println(qh(20)); } //求阶乘 public static int jc(int j){ int s = 1; int i = 1; while(i<=j){ s *= i; i++; } return s; } //求和 public static double qh(int j){ double s = 0; int i=1; while(i<=j){ s = s +1/jc(i); i++; } return s; }}

1+ 1/((1+2)*2/2)+1/((1+3)*3/2)++1/((1+n)*n/2)=2/(1*2)+2/(2*3)+2/(3*4)++2/(n*(n+1))=2*(1-1/2+1/2-1/3+1/3-1/4+1/n-1/(n+1))=2*(1-1/(n+1)) 原式等价于2*n/(n+1) 直接算吧

#include <stdio.h> void main() { int i, n; float s=0.0; scanf("%d", &n); for (i = 1; i <= n; i ++) s += 1.0/n/(n+1); printf("%f\n", s); }

#include "stdio.h"double calcS(double t){int i = 1;double retValue = 0;double sglValue = 1;double dFenzi = 0;double dFenmu = 1;do {dFenzi += 1;dFenmu *= (i+1);sglValue = dFenzi/dFenmu;retValue += sglV

k++应该在for循环里!for循环只针对对应的下行语句,所以for循环没走k++这个语句!还有你s3定义的类型也是不对的,s3应该是float吧?小数嘛.最后输出记得f%哦!

//很好实现,分有点少吧,嘿嘿//为了简单起见,我直接使用前n项和公式 s = n(n + 1 ) / 2#include int main(void){int n;long long int result = 0;printf("请输入项数n\n");scanf("%i",&n);for(int i = 0;i 评论0 0 0

dim n as integerdim sum as doublen=val(inputbox("输入一个不为零的整数"))for i = 1 to n if i=1 then sum=1 sum=sum&amp;"+"&amp; (1/n) next i call msgbox("结果为"&amp;sum)

源程序如下: #include<stdio.h>void main(){int k,a;float s=0;scanf("a=%d,n=%d",&a,&n);printf("s=1+1/2+1/3+1/4++1/n\n");for(k=1;k<=n;k++){s=s+1.0/k;if (s>a) break;}printf("1+1/2++1/n=%.6lf\n",s);}测试如下:输入a=3,n=11输出1+1/2++1/n=3.0199

c++程序设计设s=1+1/2+1/3+.+1/n,求与 匿名 分享到微博 提交回答 1 问: c程序设计求一本教授c语言程序设计流程的书和c语言编的赛车游戏源码 答: 详情>> 2 求《标准c程序设计》第四版习题解答

相关搜索:

网站地图

All rights reserved Powered by www.5213.net

copyright ©right 2010-2021。
www.5213.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com