码迷,mamicode.com
首页 > 其他好文 > 详细

16.有一分数序列 1/2,2/3,3/5,5/8,8/13,13/21,…求出这个序列的前200 项之和

时间:2014-08-05 22:29:40      阅读:815      评论:0      收藏:0      [点我收藏+]

标签:使用   os   io   for   问题   div   res   ios   

使用向量:
#include<iostream>
#include<vector>
using namespace std;
int FenShu(int);

int main()
{
    double sum=0,sum1=0;
    for(int i=2;i<=200;i++)
    {
        sum1+=FenShu(i);
    }
    sum=sum1+0.5;
    cout<<sum<<endl;
    return 0;
}

int FenShu(int index)
{
    double temp;
    vector<int> a(2,1);
    a.reserve(3);
    a.at(0)=1;
    a.at(1)=2;
    for(int i=2;i<=index;i++)
    {
        a.insert(a.begin(),a.at(0)+a.at(1));//好SB的问题,begin后得有括号
        a.pop_back();
        temp=((a.at(1))/(a.at(0)));
    }
    return temp;
}

16.有一分数序列 1/2,2/3,3/5,5/8,8/13,13/21,…求出这个序列的前200 项之和,布布扣,bubuko.com

16.有一分数序列 1/2,2/3,3/5,5/8,8/13,13/21,…求出这个序列的前200 项之和

标签:使用   os   io   for   问题   div   res   ios   

原文地址:http://www.cnblogs.com/jixiaowu/p/3893229.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!