Skip to content

Instantly share code, notes, and snippets.

@kant-shashi
Created April 19, 2013 05:41
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 kant-shashi/5418356 to your computer and use it in GitHub Desktop.
Save kant-shashi/5418356 to your computer and use it in GitHub Desktop.
finding factorial of large integer like 100 is easy in python as it has inbuilt support for such large integer but c is not fortunate enough. This C code tries to give such power to the user. You can easily find factorial of very large number. I have successfully calculated factorial of an integer as large as 15000.
/* This program is for finding the factorial of a number.
Author: Shashi Kant
*/
#include<stdio.h>
int main()
{
int a[1000000];
long long unsigned int num,f,z,temp;
scanf("%lld",&num);
int i,j;
f=num;
for (i=0;num>0;i++,num /=10)
a[i]=num%10;
while((--f)>1)
{
temp = 0; z=0;
for (j=0;j<i;j++)
{
z = f * a[j] + temp;
a[j] = z%10;
temp = z/10;
}
while(temp)
{
a[j++] = temp%10;
temp /=10;
}
i=j;
}
for(--i;i>=0;i--)
printf("%d",a[i]);
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment