Chapter - 6: Functions And Pointers

Write a recursive function to obtain the first 25 numbers of a Fibonacci sequence. In a Fibonacci sequence the sum of two successive terms gives the third term. Following are the first few terms of the Fibonacci sequence:


G
Sections
5
Exercises

1 1 2 3 5 8 13 21 34 55 89...


#include<stdio.h>
#include<conio.h>

void fs(int first, int second, int term);

int main()
{
	fs(0, 1, 25);
	_getch();
	return 0;
}

void fs(int fis, int sec, int term)
{
	int num;
	if (term == 0)
		return;
	num = fis + sec;
	fis = sec;
	sec = num;
	printf("%d, ", num);
	fs(fis, sec, term - 1);
}

© 2021 Garbage Valuegarbage value logo