BigInteger factorial program
import java.math.*;
class BigFactorial
{
static BigInteger factorial(BigInteger n)
{
BigInteger one = new BigInteger("1");
if (n.equals(one))
return one;
return n.multiply(factorial(n.subtract(one)));
}
public static void main(String...s)
{
BigInteger num1,num2,fact,counter;
BigInteger one = new BigInteger("1");
num1 = new BigInteger(s[0]);
num2 = new BigInteger(s[1]);
counter = num1;
while (!counter.equals(num2.add(one)))
{
fact = factorial(counter);
System.out.println(counter +"!="+fact);
counter=counter.add(one);
}
}
}
class BigFactorial
{
static BigInteger factorial(BigInteger n)
{
BigInteger one = new BigInteger("1");
if (n.equals(one))
return one;
return n.multiply(factorial(n.subtract(one)));
}
public static void main(String...s)
{
BigInteger num1,num2,fact,counter;
BigInteger one = new BigInteger("1");
num1 = new BigInteger(s[0]);
num2 = new BigInteger(s[1]);
counter = num1;
while (!counter.equals(num2.add(one)))
{
fact = factorial(counter);
System.out.println(counter +"!="+fact);
counter=counter.add(one);
}
}
}
Comments
Post a Comment