Programming Blog

This blog is about technical and programming questions and there solutions. I also cover programs that were asked in various interviews, it will help you to crack the coding round of various interviews

Monday, 6 November 2017

c program to print Fibonacci series with recursion

#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