您的位置:首页 > 其它

分数求和

2014-09-16 19:10 218 查看
Description
有一分数序列: 2/1 3/2 5/3 8/5 13/8 21/13......
求出这个数列的前N项之和,保留两位小数。

N


Sample Input

10


Sample Output

16.48

 

#include<iostream>

 using namespace std;

  int main()

{

    
float s=2,x=2;

  int i=2,n;

    
cin>>n;

    
while (i<=n)

    
{

       
x=1/x+1;

  s=s+x;

  i=i+1;

    
}

       
cout.setf(ios::fixed);

        
cout.precision(2);

       
cout<<s<<endl;

      
 return 0;

  

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: