Get the answers you need at Westonci.ca, where our expert community is always ready to help with accurate information. Get quick and reliable answers to your questions from a dedicated community of professionals on our platform. Join our Q&A platform to connect with experts dedicated to providing accurate answers to your questions in various fields.
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;
}
Thank you for choosing our platform. We're dedicated to providing the best answers for all your questions. Visit us again. We hope you found what you were looking for. Feel free to revisit us for more answers and updated information. Your questions are important to us at Westonci.ca. Visit again for expert answers and reliable information.