#include<iostream.h> #include<conio.h> long fibonacci(int); main() { clrscr(); int number; long result; cout<<"\n Enter the number = "; cin>>number; cout<<"\n The fibonacci series upto the "<<number<<"_th term is : " <<endl; for(int count=0;count<=number;count++) { result=fibonacci(count); cout<<" "<<result; } cout<<"\n\n The "<<number<<"_th term of fibonacci series = "<<result <<endl; getch(); return 0; } /*************************************************************************///--------------------------- fibonacci(int) --------------------------///*************************************************************************/long fibonacci(int n) { if(n==0 || n==1) return n; elsereturn fibonacci(n-1)+fibonacci(n-2); }
No comments:
Post a Comment