Skip to content

Instantly share code, notes, and snippets.

@MinhasKamal
Last active February 13, 2017 07:39
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 MinhasKamal/9286784 to your computer and use it in GitHub Desktop.
Save MinhasKamal/9286784 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment