At Westonci.ca, we connect you with the answers you need, thanks to our active and informed community. Get quick and reliable solutions to your questions from a community of experienced professionals on our platform. Connect with a community of professionals ready to provide precise solutions to your questions quickly and accurately.
Sagot :
Answer:
i hope this helpful for you
Explanation:
Example 1.
#include <iostream>
using namespace std;
int main() {
int n, t1 = 0, t2 = 1, nextTerm = 0;
cout << "Enter the number of terms: ";
cin >> n;
cout << "Fibonacci Series: ";
for (int i = 1; i <= n; ++i) {
// Prints the first two terms.
if(i == 1) {
cout << t1 << ", ";
continue;
}
if(i == 2) {
cout << t2 << ", ";
continue;
}
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;
cout << nextTerm << ", ";
}
return 0;
}
Example 2.
#include <iostream>
using namespace std;
int main() {
int t1 = 0, t2 = 1, nextTerm = 0, n;
cout << "Enter a positive number: ";
cin >> n;
// displays the first two terms which is always 0 and 1
cout << "Fibonacci Series: " << t1 << ", " << t2 << ", ";
nextTerm = t1 + t2;
while(nextTerm <= n) {
cout << nextTerm << ", ";
t1 = t2;
t2 = nextTerm;
nextTerm = t1 + t2;
}
return 0;
}
We appreciate your visit. Hopefully, the answers you found were beneficial. Don't hesitate to come back for more information. We appreciate your time. Please come back anytime for the latest information and answers to your questions. Westonci.ca is here to provide the answers you seek. Return often for more expert solutions.