Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   C++ Program Enter number and print Fibonacci series upto that nth number (http://www.go4expert.com/forums/cpp-program-enter-print-fibonacci-t29934/)

jeenu 18Dec2013 14:56

C++ Program Enter number and print Fibonacci series upto that nth number
 
Hi friends, would like to share something if Anyone wanted to know the C++ fibonacci program in simple way can go through this
Code:

// Program name : test051.c
// Print Fibonica series of nth numbers
#include <iostream.h>
#include <conio.h>
void main()
{
int n, first = 0, second = 1, third = 0;
clrscr();
cout <<"Enter Fibonica n th number : ";
cin >> n;
cout<<first<<" "<<second<<" ";
for(int i = 3; i <= n; i++)
{third = first + second;
cout<<third<<" ";
first = second;
second = third;
}
getch();
}

Output
Enter Fibonacci nth number : 10
0 1 1 2 3 5 8 13 21 34

Enter Fibonacci nth number : 15
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377

As i am a beginner,i am learning all programming languages in simple way with easy solutions.


All times are GMT +5.5. The time now is 07:52.