forked from python4geeks/Hactoberfest2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BigFactorial.java
47 lines (38 loc) · 1.18 KB
/
BigFactorial.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*Code to find the factorial of numbers whose factorial value might exceed the digit holding capacity of double also
and count the number if zeros*/
import java.util.*;
public class BigFactorial {
public static void main(String args[]){
int i,j,n,d=1,carry=0,p,g=0,c=0,a[];
a=new int[500000];
a[0]=1;
Scanner sc= new Scanner(System.in);
System.out.println("Enter the number, you want to find the factorial of");
p=sc.nextInt();
// if(p>=500)
// a=new int[1000000]; //depending upon the config of machine one may prefer to use an array of [1000000]
for(i=2;i<=p;i++)
{
for(j=0;j<d;j++)
{
n=(a[j]*i)+carry;
a[j]=n%10;
carry=n/10;
}
while(carry>0)
{
a[d++]=carry%10;
carry/=10;
}
}
for(i=d;i>=0;i--)
{
if(a[i]==0)
c++;
else if(a[i]!=0)
c=0;
System.out.print(a[i]);
}
System.out.println("\n\nzero=\n"+c);
}
}