Last active
April 13, 2019 04:36
-
-
Save ayushprd/6fbb775f39d8dfdee9b46abeec07cbfa to your computer and use it in GitHub Desktop.
Fibonacci upto n using recursion
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> | |
int fact(int n); | |
int main(){ | |
int num; | |
scanf("%d", &num); | |
int i = 0; | |
while(i != num){ //calling the factorial function upto n times | |
printf("%d \n", fact(i)); | |
i = i + 1; | |
} | |
return 0; | |
} | |
int fact(int n){ | |
if (n == 0 || n == 1) | |
return n; | |
else | |
return (fact(n-1) + fact(n-2)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment