Answer to Question #188400 in C++ for naura

Question #188400

the fibonacci sequence is a set of numbers that starts with a zero, followed by a one and proceeds based on the rule that each number( called a Fibonacci number) is equal to the sum of the first two numbers. the Fibonacci sequence is denoted by F(n), where n is the first term in the sequence. the following equation is obtained when n= 0, where the first two terms are 0 and 1 , and each subsequent number is the sum of the previous two numbers


1
Expert's answer
2021-05-19T14:42:20-0400
#include <iostream>
using namespace std;


int main() {
	int numberTerms;
	int term1 = 0;
	int term2 = 1;
	cout << "Enter the number of terms: ";
	cin >> numberTerms;
	if (numberTerms>=1){
		cout << "The Fibonacci sequence:\n";
		cout<<term1 << " ";
		for (int i = 1; i < numberTerms; i++){
			cout<<term2<< " ";
			int next = term1 + term2;
			term1 = term2;
			term2 = next;
		}
	}
	cout<<"\n\n";
	system("pause");
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS