Last active
February 13, 2017 07:39
-
-
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'.
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
/** | |
* 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was really amazed by sensing the power of a simple program like this. 😃