Write a program that uses recursive function fibo() that generates a Fibonacci series containing N elements.
CODING:
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
long int i;
long int fibo(int n);
clrscr();
printf("\nEnter The Number:");
scanf("%d",&n);
i=fibo(n);
printf("\nThe %d Fibonocik Number is=%d",n,i);
getch();
}
long int fibo(int n)
{
int old_no,current_no,sum,i;
i=1;
old_no=0;
current_no=1;
whilex(i<=n)
{
sum=old_no+current_no;
old_no=current_no;
current_no=sum;
i++;
printf("\nSUM=%d",sum);
}
return(sum);
}
OUTPUT:
CODING:
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
long int i;
long int fibo(int n);
clrscr();
printf("\nEnter The Number:");
scanf("%d",&n);
i=fibo(n);
printf("\nThe %d Fibonocik Number is=%d",n,i);
getch();
}
long int fibo(int n)
{
int old_no,current_no,sum,i;
i=1;
old_no=0;
current_no=1;
whilex(i<=n)
{
sum=old_no+current_no;
old_no=current_no;
current_no=sum;
i++;
printf("\nSUM=%d",sum);
}
return(sum);
}
OUTPUT:
Comments
Post a Comment