c语言编程:1、求1+1/2+1/3+1/4+……+1/20的结果 2、求1-1/2+1/3-1/4+1/5-1/6+……-1/20的结果

如题所述

1)
#include<stdio.h>
int main()
{int i;
 double s=0;
 for(i=1;i<=20;i++)
   s+=1.0/i;
 printf("%g\n",s);
 return 0;
}

2)
#include<stdio.h>
int main()
{int i;
 double s=0;
 for(i=1;i<=20;i++)
   if(i%2)s+=1.0/i;
     else s-=1.0/i;
 printf("%g\n",s);
 return 0;
}

温馨提示:内容为网友见解,仅供参考
无其他回答

...20的结果 2、求1-1\/2+1\/3-1\/4+1\/5-1\/6+……-1\/20的结果
int main(){ int i;double sum1,k=1,sum2;for(i=1,sum1=0;i<=20;i++)sum1+=k\/i;for(i=1,sum2=0;i<=20;i++){ sum2+=k\/i;k*=-1;} printf("%lf %lf\\n",sum1,sum2);return 0;}

C语言程式设计序:计算数列1+1\/2+1\/3+1\/4+.+1\/100的和并输出 帮一下 吧...
include<stdio.h>long fun(int n){int i;long s=1;for(i=1;i<=n;i++) s=s*i;return s;}void main(){int i;double sum=0;for(i=1;i<=10;i++)sum=sum+1.0\/fun(i);printf("sum=%f\\n",sum);} c语言程式设计:输出如下序列的前20项.s=1+1\/2-1\/3+1\/4-1\/5+1\/6-...

c编程求1+1\/2!+1\/3!+……1\/20!
include <stdio.h> int main (){ double Sum=0.0;int i,Value=1;for(i=1;i<=20;i++){ Value*=i;Sum+=1.0\/Value;} printf("1+1\/2!+...+1\/20!=%lf",Sum);return 0;}

c语言 计算 1-1\/2+1\/3-1\/4+…+1\/19-1\/20.
include<cmath> int main(){ double sum=0;for(int i=1;i<=20;i++){ sum=sum+(pow(-1,i+1))*(1.0\/i);} cout<<"1-1\/2+…"<<"+1\/19-1\/20"<<"=";cout<<sum;return 0;}

用C语言计算1\/2+1\/3+1\/4+1\/5...+1\/n的前20项的结果
main(){int i,n;float s=0.0;scanf("%d",&n);for(i=2;i<=n;i++)s=s+1.0\/i;printf("%f",s);}

c语言求1+1\/2+1\/4+1\/6+1\/8+1\/10+1\/12+1\/14+1\/16+1\/18+1\/20?
int i;float t,s=1;for (i=1;i<=10;i++){ t = 1.0\/(2*i);s += t;printf("%d %.4f %.4f\\n",i,t,s);} printf("%f\\n",s);

C语言:用for循环语句编程输出1—20之间的所有整数,两数之间以空格分隔...
\/*6、求前n个偶数和*\/ int main(int argc, char **argv){ int n;int i,sum;do{ printf("Please input a number(>0):");scanf("%d",&n);}while(n>0);for(i=1,sum=0;i<=n;i++)sum += 2*i;printf("sum=%d",sum);} \/*7、求1+1\/2+……+1\/200*\/ int main(int ...

c语言求1\/1!+1\/2!+1\/3!+1\/4!……+1\/n! =e 且n=20
include <stdio.h> float jc(int n){ int j;float p=1;for(j=1;j<=n;j++)p=p*j;return p;} int main(){ int i;float e=1;for(i=1;i<=20;i++)e+=1\/jc(i);printf("e=%f\\n",e);return 0;}

C语言S=1+1\/2+1\/4+1\/7+1\/11+...,求前20项结果。
include <stdio.h>int main(){ double s=0; int i; int n=1; for(i = 0; i<20; i++) { n+=i; s+=1.0\/n; } printf("%lf\\n", s); return 0;}

c语言1+1\/2+1\/3+1\/5+1\/8+1\/13+。。。前二十项和
分母是斐波那契数列。main(){ int i;double n, n_1, n_2, sum;n = 1;n_1 = 1;n_2 = 0;sum = 0;for(i=0; i < 20; i++){ sum += 1\/n;n_2 = n_1;n_1 = n;n = n_1 + n_2;} printf("%lf", sum);} ...

相似回答