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
#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;
}
Comments