Skip to content

Instantly share code, notes, and snippets.

@SohanChy
Created August 8, 2015 05:51
Show Gist options
  • Save SohanChy/0aad31008c43c927aa66 to your computer and use it in GitHub Desktop.
Save SohanChy/0aad31008c43c927aa66 to your computer and use it in GitHub Desktop.
Factorial in C using Recursion
#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