Answer to Question #306231 in C++ for Navy

Question #306231

Write a c++ program to display the Fibonacci series of the first 50 integer numbers.

1
Expert's answer
2022-03-04T17:02:17-0500
#include <iostream>
#include <iomanip>
using namespace std;

int main() {
    long long f1=0, f2=1, f;
    
    cout << setw(2) << 1 << ": " << setw(10) << f1 << endl;
    cout << setw(2) << 2 << ": " << setw(10) << f2 << endl;

    for (int i=3; i<=50; i++) {
        f = f1 + f2;
        f1 = f2;
        f2 = f;
        cout << setw(2) << i << ": " << setw(10) << f2 << endl;
    }

    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!

Leave a comment

LATEST TUTORIALS
New on Blog