Write a recursive function to print the first 25 elements of fibonacci series
fibonacci series is characterized by the fact that every number after the first two is the sum of the two preceding ones
solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <ctype.h> | |
#include <math.h> | |
#include <stdbool.h> | |
void fibonacci25(int start,int current) | |
{ | |
int next; | |
static int t=23; | |
if(t--) | |
{ | |
next=start+current; | |
start=current; | |
current=next; | |
printf("%d\n",next); | |
fibonacci25(start,current); | |
} | |
return; | |
} | |
int main() | |
{ | |
int start=0; int current=1; | |
printf("%d\n%d\n",start,current);//print first two terms 0,1 | |
fibonacci25(start,current);//function that print first 25 number of fibonacci series | |
return 0; | |
} |
No comments:
Post a Comment