Question #37452

Write a program that prints the following elements of this serial
1 1 2 3 5 8 13 21 34 55

Definition of this sequence: this serial collects number with two numbers before.

With my pleasure if you help me
1

Expert's answer

2013-12-03T11:10:13-0500
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    int next = 1,
        now = 1,
        before = 0;
    cout << now << ' ' << next << ' ';
    for(int i = 0; i < 8; i++)
    {
        int temp = now;
        next += now;
        now += before;
        before = temp;
        cout << next << ' ';
    }
    cout << endl;
    cin.get(); cin.get();
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS