Fibonacci Series Program in C++
Hello friends; Hitesh is here; Today we discuss how to write fibonacci series program in c++. In the Fibonacci series, the first two numbers in the Fibonacci series are 0 and 1, and each subsequent number is the sum of the previous two. Series are; 0, 1, 1, 2, 3, 5, 8, 13..........Steps to write Code:
In general, it is a simple concept just add two previous numbers and print next term of the Fibonacci series.
Code of Fibonacci Series
#include<iostream.h>
#include<conio.h>
int main()
{
int a=0,b=1, c,n;
cout << "Enter the value of n ";
cin >> n;
cout << endl << a <<" " <<b << " " ;
for(int i =0; i<(n-2); i++)
{
c = a+ b;
cout << c << " ";
a=b;
b=c;
}
Output:
Enter value of n 7
0, 1, 2, 3, 5, 8, 13
No comments:
Post a Comment