WAP to print the Fibonacci sequence up to a given term using function

Write a program to print the Fibonacci sequence up to a given term using function

#include<stdio.h>

int fibonacci(int);

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

int fibonacci(int n) {
	int i,a=0,b=1,next;
	for(i=1;i<n;i++) {
		next=a+b;
		a=b;
		b=next;
	}
	return a;
}

Output

Enter term:
4
0 1 1 2

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