Created
February 6, 2015 10:37
-
-
Save shivamMg/3637c7f59a07d656834f to your computer and use it in GitHub Desktop.
Calculate factorial of 100 in C.
This file contains hidden or 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
#include <stdio.h> | |
int main(void) { | |
int carry,i,j,x,lenArr; | |
int N = 100; // Factorial of 100 | |
int Arr[158] = {0}; // Factorial of 100 is approximately 9 * 10^157 => 157 digits | |
Arr[0] = 1; | |
lenArr = 1; // Number of elements in Arr | |
carry = 0; | |
for(i=1;i<=N;i++) { | |
for(j=0;j<lenArr;j++) { | |
x = Arr[j]*i + carry; | |
Arr[j] = x%10; | |
carry = x/10; | |
} | |
while(carry>0) { | |
Arr[lenArr] = carry%10; | |
carry = carry/10; | |
lenArr++; | |
} | |
} | |
for(i=lenArr-1;i>=0;i--) | |
printf("%d",Arr[i]); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment