一道C语言编程题求s=1+1/2!+1/3!+1/4!+....+1/n!的的近似值,星号下填语句

如题所述

图片中各项的分母不是阶乘 而是平方。 

应该是你题目打错了。 

按照图片中填写代码如下

double r=0;
int i;
for(i = 1; i <=n; i ++)
    r+=1.0/i/i;
return r;
温馨提示:内容为网友见解,仅供参考
第1个回答  2017-05-19
int i,j,t;
double s=0;
for(i=1;i<=n;i++)
{ t=1;
for(j=1;j<=i;j++)
t=t*j;
s=s+1.0/t;

}
return s;
第2个回答  2018-05-05

#include<iostream>

#include<cstdio>

#include<cstring>

using namespace std;

string a,b;

int main()

{

cin>>a>>b;

if(a.find(b)!=b.npos)

cout<<"yes";

else if(b.find(a)!=b.npos)

cout<<"yes";

else cout<<"no";

return 0;

}

编写程序计算s=1+1\/2!+1\/3!+1\/4!+...1\/n!
int p; for (p=1;p<=n;p++) result=result + 1\/factorial(p);\/\/累加 return result;}double factorial(int m){ double result=1;\/\/“0”的阶乘是“1” int i; for (i=1;i<=m;i++) result=result*i; return result;}\/*看到好多人踩我的答案,然后我觉...

用C语言编程s=1+1\/2!+1\/3!+1\/4!+……+1\/n!其中n的值由键盘输入(急...
double s=0;for(int i=1;i<=n;i++)s+=1.0\/a(i);printf("%f",s);}

用C++编程s=1+1\/2!+1\/3!+1\/4!+……+1\/n 求恰好使s大于x的值 (急呀)
直接上代码如下,因为代码用到了阶乘,注意不要溢出。include <iostream> long greatherThan(double x){ double s = 0.0f;long result = 1;long temp = 1;while(s < x){ temp = temp * result;s += (1.0 \/ temp);result++;} return result - 1;} int main(){ std::cout << ...

编写C程序,求1+1\/1!+1\/2!+1\/3!+1\/4!+...+1\/n!
include<iostream> using namespace std;int main(){ int n;double sum = 0;int a = 1;cout << "Please input the 'n': ";cin >> n;for(int i = 1;i <= n;i++){ for(int j = 1;j <= i;j++){ a = a*j;} sum = sum + (double)1\/(double)(a);} cout << "...

C语言 分数计算怎么编 如1+1\/2+1\/3+1\/4+……1\/n ?
include<stdio.h> int main(void){ int n;scanf("%d",&n);int i;double sum=0;double sign=1.0;for(i=1;i<=n;i++){ sum=sum+sign\/i;sign=-sign;} printf("f(%d)=%f\\n",n,sum);return 0;}

...s=1+1\/(1+2)+1\/(1+2+3)+1\/(1+2+3+4)+...+1\/(1+2+3+...+n)_百度知...
include <stdio.h> int main(){ double s=0;int n,t=0;printf("请输入n\\n");scanf("%d",&n);int i;for(i=1;i<=n;i++){ t+=i;s+=1.0\/t;} printf("结果为:%f",s);return 0;}

用c++求1+1\/2+1\/3+1\/4+1\/n的近似值,要求至少累加到1\/n不大于0.00984为止...
include <stdio.h>int main(){int n; double s=0; n=1; do {s+=1.0\/n; }while(1.0\/n++>0.00984); printf("n=%d\\ns=%.8lf\\n",--n,s); return 0;}

C语言 求和1+1\/2!+1\/3!+1\/4!+……+1\/n!
第一个空:sum=0 第二个空:i++ 第三个空:1\/t

用C语言求s=1-1\/2!+1\/3!-1\/4!+……+1\/n!其中n的值由键盘输入(急!!)
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) ...

c语言1+1\/2+1\/3+1\/4……1\/n,求前n项和,并且输出公式,1+1\/2+1\/3=xxx
argc,char *argv[]){ int n,i;double s;printf("Enter n(int 0<n)...\\n");if(scanf("%d",&n)!=1 || n<1){ printf("Input error, exit...\\n");return 0;} s=0.0,i=1;while(i<=n)s+=1.0\/i++;printf("1+1\/2+1\/3+...+1\/n = %g\\n",s);return 0;} ...

相似回答