SnapTimes

News In A Snap!!

C++ Programs: Generate a Fibonacci Series

June 2, 2015

C++_Main

What is Fibonacci Series?

A series of numbers in which each number ( Fibonacci number ) is the sum of the two preceding numbers. The simplest is the series 1, 1, 2, 3, 5, 8, etc.

Code


#include<iostream.h>

#include<conio.h>

// Program to generate a Fibonacci Series

int main() {

clrscr();

long x=0, y=1;

int seriesLength = 15;

cout << "Enter the length of the series: ";

cin >> seriesLength;

for (int i=0; i<seriesLength; i++)

{

cout << x << " ";

long t = y;

y += x;

x = t;

}

cout << endl;

getch();

return 0;

}

Output:

fib


SnapTimes.in | Get Tech Addicted...
About Us | Contact Us | ©2017