Wednesday 1 June 2016

Write a program that enters and integer form the user and displays the Fibonacci numbers.

#include<iostream.h>
#include<conio.h>
void fibonacci(int n);
void main()
{
       int num;
       clrscr();
       cout<<"Enter number upto which fibonacci numbers are required: ";
       cin>>num;
       cout<<"Fibonacci  numbers upto "<<num<<" are: "<<endl;
       fibonacci(num);
       getch();
}
void fibonacci(int n)
{
       int a , b, next;
       a = 0;
       b = 1;
       cout<<a<<" "<<b;
       next = a+b;
       while(next <= n)
       {
              cout<<" "<<next;
              a = b ;
              b = next;
              next = a+b;
       }
}

Share:

0 comments:

Post a Comment

Popular Posts

Recent Posts

Unordered List

Text Widget

Pages

About Me

My photo
A group of two, with a little hope of helping beginners to learn how to code :)
Powered by Blogger.

Comments

Facebook

Ad Home

Follow Us

Random Posts

Sponsor

Recent Posts

Header Ads

Popular Posts

Copyright © Functions in C++ | Powered by Blogger

Design by ThemePacific | Blogger Theme by NewBloggerThemes.com | Distributed By Blogger Templates20