#include<stdio.h>
#include<conio.h>
int fibonacci(int prev, int number);
void main() {
int size;
static int prev = 0, number = 1;
clrscr();
printf("Enter the Size of Series (< 20) : ");
scanf("%d", &size);
printf("1 ");
fibonacci(prev, number);
getch();
}
int fibonacci(int prev, int number) {
static int i = 1;
int next_num;
if (i == size)
return (0);
else {
next_num = prev + number;
prev = number;
number = next_num;
printf("%d ", next_num);
i++;
fibonacci(prev, number);
}
return (0);
}
No comments:
Post a Comment