Skip to content

@MinhasKamal /BigFactorial.c
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
It is a little program that theoritically can find out factorial of any number. You have to just change the value of the variable 'DIGIT'.
/**
* Developer: Minhas Kamal
* Date: August-2013
* Comment: The program can find very big factorial result, and it can be changed by changing 'DIGIT' value.
**/
#include <stdio.h>
#define DIGIT 10000000 //change accordingly
int main()
{
while(1)
{
short int a[DIGIT+1];
int x, i;
for(i=0; i<DIGIT+1; i++) a[i]=-1;
printf("Enter your integer : ");
scanf("%d", &x);
if(x<1) break;
int j;
i=x;
for(j=DIGIT; i>0; j--)
{
a[j]=i%10;
i=i/10;
}
int k=0;
for(i=x-1; i>0; i--)
{
for(j=DIGIT; a[j]>=0; j--)
{
k=(i*a[j])+k;
a[j]=k%10;
k=k/10;
}
a[j]=k%10;
k=k/10;
a[j-1]=k;
for(k=0; a[k]<1; k++) a[k]=-1;
k=0;
}
for(i=0; a[i]<1; i++);
for(; i<DIGIT+1; i++) printf("%hd", a[i]);
printf("\n\n");
}
return 0;
}
@MinhasKamal
Owner

I was really amazed by sensing the power of a simple program like this. :smiley:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.