WAP to print the Fibonacci series up to nth term

Write a program to print the Fibonacci series up to nth term using recursive function

#include<stdio.h>

int fibo(int);

int main() {
	int i,n;
	printf("Enter term: ");
	scanf("%d",&n);
	
	for(i=1;i<=n;i++) {
		printf("%d\t",fibo(i));
	}
	return 0;
}

int fibo(int n) {
	if(n==1)
		return 0;
	else if(n==2)
		return 1;
	else
		return fibo(n-1)+fibo(n-2);
}

Output

Enter term: 5
0 1 1 2 3

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments