jingxinwu.net
当前位置:首页>>关于求分数序列前n项和的资料>>

求分数序列前n项和

#include<stdio.h> int main() { double sum = 0, a = 1, b = 2; int n; scanf("%d", &n); for (int i = 0;i < n;i++) { sum += b / a; b += a; a = b - a; } printf("%.4f\n",sum); return 0; }

#define _CRT_SECURE_NO_WARNINGS/*vs2013编译器需要*/#include <stdio.h>#include <stdlib.h>#include <string.h>#define DEF_ARR_NUM 1024 int main() { int arr[DEF_ARR_NUM]; int i = 0; int n = 0; int Size = 0; int sum = 0; printf("输

1+2+3++n+n+1=(n+2)(n+1)/2所以通项公式为2/(n+2)(n+1)=2(1/n+1-1/n+2)所以前n相和为:S=2(1/2-1/3+1/3-1/4+1/4-1/n-1/n+1+1/n+1-1/n+2)=2(1/2-1/n+2)=n/n+2

1、公式法.等差(比)数列公式求和(注意等比公比的讨论);2、倒序求和.等差求和公式就是这样的;3、裂项求和.如:an=1/[n(n+1]=1/n-1/(n+1);4、错错位法.如:an=(2n-1)*2^n.

# include <stdio.h> main() { int i,j,n,k,t; double sum=2; printf("input a number:\n"); scanf("%d",&n); j=2; k=1; for(i=1;i<n;i++) // 当n大于或等于2时会循环. { t=k; k=j; j=j+t; sum += j/k; } printf("前%d项和为%f\n",n,sum); }

#include int sn(int n){ float x=2,y=1,i=1,s=0; for(i=1;i 评论0 0 0

解:因为an=8n/[(2n-1)(2n+1)]=[(2n+1)-(2n-1)]/[(2n-1)(2n+1)]=1/(2n-1)-1/(2n+1)于是Sn=a1+a2++an=1/1-1/3+1/3-1/5+1/5-1/7++1/(2n-1)-1/(2n+1)=1-1/(2n+1)=(4n+4n)/(2n+1)

#include<stdio.h> void main() { int n; double s, t; s = 0; for (n = 1; n <= 20; n++) { t = 1.0 / (2 * n);//1为整型,如果结果为浮点型,那么要用1.0, s = s + t; } printf("前20项之和为:%f", s);//%d改为%f getchar(); }

#includevoid main(){ int n, k = 1; float fm = 1.0, fz = 2.0, sum = 0, temp; scanf("%d",&n); while(k void main(){ int n; printf("please enter a integer number :"); scanf("%d",&n); int y, c, sum = 0; while((n / 10) != 0){ y = n % 10; n = n / 10; sum = sum + y; } printf("result : %d",(sum + n));}

#includevoid main(){int i,t,n=20;float a=2,b=1,s=0;for(i=1;i 评论0 0 0

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