dfkt.net
当前位置:首页 >> 大佬求解C语言编程 求以下公式的值 s=1+1/(1*2)+1(2*3)+…1/(n*(n+1) >>

大佬求解C语言编程 求以下公式的值 s=1+1/(1*2)+1(2*3)+…1/(n*(n+1)

#include void main () { int n,deno = 1; float temp; float s = 1.0; printf ("输入n:"); scanf ("%d",&n); while (deno { temp = (float)1/(deno*(deno+1)); s += temp; deno++; } printf ("s=%f\n",s); }

结果可以验证 s=1+1/(1*2)+1/(2*3)++1/(n*(n+1)) = 1+1-1/n+1#include "stdafx.h"#include <iostream>#include <iomanip>// s=1+1/(1*2)+1/(2*3)++1/(n*(n+1))#define N 1000int _tmain(int argc, _TCHAR* argv[]){ double dResult, dResult1; int n=1;

12345678910 #include voidmain(){inti,n;doubles=1;scanf("%d",&n);for(i=1;is+=1.0/(i*(i+1));printf("s=%f",s);}

#include <stdio.h> double factorial(int n) { double f = 1 ; for (int t=1 ; t<= n ; t++) { f = f*t ; } return f; } void main() { int n, k=1; double s = 0 ; printf("Input n\nn=") ; scanf("%d", &n) ; for (int t=1; t<=n; t++) { s = s + ((double)k)/factorial(t) ; k = -k ; } printf("s=%f\n", s) ; }

int main() { int n,i; double s = 0; scanf("%d",&n); for(i = 1;i <= n;i++) { s += 1/(double)(i*i); } printf("%f\n",s); return 0; }

用一个简单的for循环加上跳出语句就可以了#include <stdio.h>void main(){double s;int i;s=0;for(i=1;i<10000;i++){s=s+1.0/(i*(i+1));if (1.0/(i*(i+1))) break;}printf("n=%d,s=%.3lf",i,s);}

n=7

#include<stdio.h> void fun(int n) { int temp = 1; double sum = 0; int i; for (i=0;i<n ;++i ) { temp = temp*(i+1); sum += 1.0/temp; } printf("%lf\n",sum); } void main() { int n; scanf("%d",&n); fun(n);//n最大不得超过13!}

//---------------------------------------------------------------------------#include <stdio.h> long int s(int n) { if (n) return n*n+(s(n-1); else return 0; } int main() { int n; scanf("%d",&n); printf("%ld",s(n)); return 0; }//---------------------------------------------------------------------------

n=1,s=0;i=1;i小于等于25;i++n=n*i;s+=1/n完了你自己按标准整理下输出结果就行了.好久没做过了,快忘了都.

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