#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;
}
}
#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;
}
}
0 comments:
Post a Comment