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.
#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;
}
Comments
Leave a comment