Answer to Question #285236 in C++ for vaness

Question #285236

Create a C++ program that inputs 2 numbers and prints them out. Then print the next 10 numbers in the sequence, where the next number is the sum of the previous two.


Sample Output:


Enter the first number: 1

Enter the second number: 3

1 3 4 7 11 18 29 47 76 123 199 322


1
Expert's answer
2022-01-06T05:38:16-0500
#include <iostream>
using namespace std;
int main(){
    int a{}, b{};


    cout<<"Enter the first number: ";
    cin>>a;
    cout<<"Enter the second number: ";
    cin>>b;
    
    for(int i = 0; i < 12; i++){
        cout<<a<<" ";
        int temp = a;
        a = b;
        b += temp;
    }
    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