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

A

B

C

D

E

F

G

1

2

3

4

5

6

7

8

9

10

11

12

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);
}

© 2020 Garbage Valuegarbage value logo