#include <iostream>
usingnamespace std;
int main ()
{
int n;
int s;
int b;
do
{
cout << "Enter Starting Number: ";
cin >> n;
if (n<1 || n>9)
cout << "Invalid Input" <<endl;
}
while (n<1 || n>9);
do {
cout << "Enter number of sequence: ";
cin >> s;
if (s<5 || s>20)
cout << "Invalid Input" <<endl;
}while (s<5 || s>20);
cout <<n <<" " <<n <<" ";
\\don't know what to use next if for loop or a simple addition
system("pause");
return 0;
}
#include <iostream>
int fibonacci(int start, int n)
{
if(n < 2) //0 or 1
return start;
elsereturn fibonacci(start, n - 1) + fibonacci(start, n - 2);
}
int main()
{
std::cout << "Please enter the starting number: ";
std::size_t start = 0u;
std::cin >> start;
std::cout << "Please enter the number of terms: ";
std::size_t terms = 0u;
std::cin >> terms;
for(std::size_t i = 0u; i < terms; ++i)
std::cout << fibonacci(start, i) << ' ';
}
Please enter the starting number: 2
Please enter the number of terms: 5
2 2 4 6 10
It would be more efficient to use an array to access the previous values since they are being accessed multiple times or to fix the function but I am very tired right now.
By the way after thinking you could simply use a loop