Answer to Question #284710 in C++ for papi

Question #284710

Enter 2 numbers and print them out. Then print the next 10 numbers in the sequence, where the

next number is the sum of the previous two.


1
Expert's answer
2022-01-07T01:49:55-0500
#include <iostream>


int main()
{
    int num1, num2;
    std::cout<<"Enter 2 numbers: ";
    std::cin>>num1>>num2;
    std::cout<<"You entered "<<num1<<" and "<<num2<<std::endl;
    for(int i = 0; i != 10; ++i)
    {
        int sum = num1 + num2;
        std::cout<<sum<<std::endl;
        num1 = num2;
        num2 = sum;
    }
    
    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