Created
April 19, 2013 05:41
-
-
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 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
/* 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