Skip to content

Instantly share code, notes, and snippets.

@ayitinya
Created April 28, 2022 08:22
Show Gist options
  • Save ayitinya/2a61ede61cf069168ced7b6a112529cd to your computer and use it in GitHub Desktop.
Save ayitinya/2a61ede61cf069168ced7b6a112529cd to your computer and use it in GitHub Desktop.
I used an unsigned long long int. In python3, there is no limit to the max int, it depends on what your system memory can take. In C, I ran the code in linux, an unsigned long has a range of 0 to 18446744073709551615.
#include <stdio.h>
unsigned long long int factorial(int n)
{
if (n == 0)
{
return 1;
}
else
{
return n * factorial(n - 1);
}
}
int main(void)
{
int n;
printf("Enter a number: ");
scanf("%d", &n);
printf("%lld\n", factorial(n));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment