#include <iostream.h>
int Fibo(int n)
{
if (n == 1)
return (0);
if (n == 2)
return (1);
return(Fibo(n-1)+Fibo(n-2));
}
void main()
{
int n;
cout << "\nEnter the value of n: ";
cin >> n;
cout << "\nThe first " << n << " numbers in the Fibonacci series are:\n\n";
for (int i = 1; i <= n; i++)
{
int num;
num = Fibo(i);
cout << num;
if (i < n)
cout << ", ";
}
}
No comments:
Post a Comment