Write a program to display Fibonacci series by writing the value to the main().... [using function & arrays]
Program:
#include<stdio.h>
#include<conio.h>
long int fibo(int n);
void main()
{
int l,i;
long int fibonacci[50];
clrscr();
printf("Enter the limit:");
scanf("%d",&l);
for(i=0;i<l;i++)
fibonacci[i]=fibo(i);
for(i=0;i<l;i++)
{
printf("%d",fibonacci[i]);
printf("\n");
}
getch();
}
long int fibo(int n)
{
if(n<=1)
return n;
else
return fibo(n-1)+fibo(n-2);
}
Sample Output:
0 comments:
Post a Comment