求指定序列之和

/*****************************************************
copyright (C), 2014-2015, Lighting Studio. Co.,     Ltd.
File name:
Author:Jerey_Jobs    Version:0.1    Date:
Description:
Funcion List:
*****************************************************/

#include

float fun(int num);

int main()
{
    int num;
 printf("Enter a number : ");
 scanf("%d",&num);
 printf("the sum before %d's count is %lf\n",num,fun(num));
    return 0;
}

float fun(int num)
{
 int j,m=2,n=1,x;
// float m = 2.0, n = 1.0;
 float k;
 double sum = 0;
 for(j = 1;j <= num;j++)
 {
  k = (float) m / n;
        sum = sum + k;
  x = m;
  m = m + n;
  n = x;
 }
 return sum;
}

你可能感兴趣的:(求指定序列之和)