Skip to content

Instantly share code, notes, and snippets.

@ayushprd
Last active April 13, 2019 04:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayushprd/6fbb775f39d8dfdee9b46abeec07cbfa to your computer and use it in GitHub Desktop.
Save ayushprd/6fbb775f39d8dfdee9b46abeec07cbfa to your computer and use it in GitHub Desktop.
Fibonacci upto n using recursion
#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