Created
August 8, 2015 05:51
-
-
Save SohanChy/0aad31008c43c927aa66 to your computer and use it in GitHub Desktop.
Factorial in C 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> | |
// Video explanation in Bangla at | |
// https://youtu.be/c8LhCLnU5bc | |
int main() | |
{ | |
int x = 3; | |
int result = factorial(x); | |
printf("Factorial of 3 = %d",result); | |
return 0; | |
} | |
int factorial(int n) | |
{ | |
// base case | |
if (n == 1) | |
{ | |
return 1; | |
} | |
// recursive case | |
return n * factorial(n - 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment