Wednesday 8 January 2014

C++ Program for Fibonacci series using constructor












Fibonacci Series:1 1 2 3 5 8 13 21 34 55





//SOURCE CODE:using constructor.....


#include<stdio.h>
#include<conio.h>
#include<iostream.h>

class fibo{
int a[100];
public:
fibo_show(int n);

}b1;
fibo::fibo_show(int n)
{a[0]=1;
int i;
a[1]=1;
for(i=0;i<n-2;i++)
{a[i+2]=a[i]+a[i+1];
 }
 for(i=0;i<n;i++)
 { cout<<a[i]<<"\t";
 }
}
main()
{int i;
clrscr();
cout<<"enter the number of terms of fibonacci series\n";
cin>>i;
b1.fibo_show(i);
getch();
}


OUTPUT:
enter the number of terms of fibonacci series
5

1 1 2 3 5


No comments:

Post a Comment