Fibonacci Numbers in C++

Write a C++ program to write fibonacci numbers. You should input the number of fibonacci numbers you want in your program.

The fibonacci sequence is given by

$$F_i = \begin{cases} F_0 = 0, \\ F_1 = 1, \\ F_n = F_{n-1}+F_{n-2} \end{cases} $$

using namespace std;
int main(){
	int f0=0,f1=1,f2;
	int n;
	cout<<"Enter the numbers of integers "<<endl;
	cout<<n<<" numbers of fibonacci are "<<f0<<" "<<f1<<" ";
		f2 = f1 + f0;
		f0 = f1;
		f1 = f2;
		cout<<f2<<" ";
	return 0;
output of the above program.  fibonacci sequence
output of the above program.

Leave a Reply