Program to print Fibonacci series
#include<iostream>
#include<conio.h>
using namespace std;
void fibonacci_Series(int
length);
int main()
{
int series_length = 0, temp = 0;
cout
<< "\n\t ______ Program to print
Fibonacci Series ______";
cout
<< "\n\n
Enter the Length of the Series - ";
cin
>> series_length;
fibonacci_Series(series_length);
getch();
return 0;
}
void fibonacci_Series(int
length)
{
int first_number = 0, second_number = 0, third_number
= 0, temp = 0;
first_number
= 0;
second_number
= 1;
cout
<< "\n\n
Fibonacci Series - " << first_number << " , " << second_number;
for(temp = 3; temp <= length; temp++)
{
third_number
= first_number + second_number;
cout
<< " , " <<
third_number;
first_number
= second_number;
second_number
= third_number;
}
}
No comments:
Post a Comment