(Fibonacci Series) The Fibonacci series is a series that begins with 0 and 1 and has the property that each succeeding term is the sum of the two preceding terms. For example, the third Fibonacci number is 1 which is sum of 0 and 1. The next is 2, which is a sum of 1 + 1. Write a program that displays the first ten numbers in a Fibonacci series

PHOTO EMBED

Tue Oct 27 2020 06:00:36 GMT+0000 (Coordinated Universal Time)

Saved by @mahmoud hussein #c++

#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{

	int f1 = 0, f2 = 1;
	int nextTerm = 0;
	for (int i = 1; i < 10; i++)
	{
		//print first 2 numbers
		if (i == 1)
		{
			cout <<  f1<<" ";
			continue;
		}
		if (i == 2)
		{
			cout << f2 << " ";
			continue;
		}
		
		nextTerm = f1 + f2;
		f1 = f2;
		//make f2 = the next term
		f2 = nextTerm;
		cout << nextTerm<<" ";

	}

	
	

	
	
}

	
	

content_copyCOPY

http://cpp.sh/