C语言:求数列1,2,3,2,3,4,3,4,5,4,5,6,…前N项和. 为一个自然数N,1≤N≤1000。输入文件最后一行为0,表示输入结束。输出数列前N项和。
纠正:C语言编程:有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13...求出这个数列的前n项之和.#includeint main(){int n,sum=0,i=2,j=1,k,m;while(scanf("%d",&n)!=EOF){for(k=1;k 相关知识点: 试题来源: 解析 #includeint main(){int n,sum=0,i=2,j=1,k,m;while(s...
include <stdio.h>int main() { int get(int, int); int n; scanf("%d, &n); int i = n / 3; int j = n % 3; printf("%d\n", 6 * i + j * (i + 1) + (int)(i == 2)); return 0;} ...
int main(int argc,char *argv[]){ int N,i,a,b;double s,t;printf("Enter N(int N>0)...\nN=");if(scanf("%d",&N)==1 && N>0){ for(a=2,b=1,s=i=0;i<N;i++)s+=a/(b+0.0),a+=b,b=a-b;printf("s(%d)≈%.4f\n",N,s);} else printf("Input error...
include<stdio.h> main(){ float *p,m=0.0,a[100]={1.0,2.0};//100个数以内 int i,n;scanf("%d",&n);if(n>=2){ for(i=2;i<=n+1;i++){ a[i]=a[i-1]+a[i-2];m=m+a[i-1]/a[i-2];}printf("%f",m);} else if(n==1)printf("2.0");else printf("...
{ int n; // 项数 float sum = 0; //和 printf( "输入一个整数:\n" );scanf( "%d", &n );if ( n < 0 ) // 处理错误输入 { printf( "error\n" );return 0;} else { int m_1 = 0;int m_2 = 1;for ( int i = 1; i <=n ; i ++ ){ sum += (double)i ...
C语言如何用数组求Fibonacci数列的前N项和Fibonacci数列就是后一项是前两项之和 1 1 2 3 5 8 13 21...依次类推。要求求前N项和,N
//从第3项开始,分子是前两项分子之和 sum+=b/a; ai=aj; bi=bj; aj=a; bj=b; } printf("前%d项的和= %.2f\n",N,sum); return 0;}示例运行结果:2 前2项的和= 3.50 20 前20项的和= 32.66 ...
void){ int n,i,a,b;double sum;while(1){printf("Input n(int n>0)...\nn=");if(scanf("%d",&n) && n>0)break;printf("Error, must n>0: ");}for(sum=0.0,a=1,b=2,i=1;i<=n;i++){sum+=b/(a+0.0);b+=a;a=b-a;}printf("The result is %g\n",sum...
int fun(int n){ if(n==2){ return (n-1)/n;}else{ return fun(n-1)+(n-1)/n;} }