Friday, 22 May 2015

Program In C++ to Print Fibonacci Numbers

print Fibonacci numbers in c++
Problem: Write a program in c++ that will print the fibonacci numbers to a limit.

Description: This is another best program in c++ which prints the fibonacci numbers. You have to enter the number till where you want to print the series.



#include<iostream>
#include<cmath>

using namespace std;

int main()
{
   unsigned long a=0,b=1,num;
   unsigned long c=0;
   cout << "Enter the number till where you want fibonacci series...... : ";
   cin >> num;
   cout << endl;
   cout << a << ", ";
   while (c<=num)
   {
      cout << b << ", ";
      c=a+b;
      a=b;  
      b=c;  
   }
   cout << endl << endl;
   system("pause");
   return 0;
}

0 comments:

Post a Comment