Algorithm


Problem link- https://www.spoj.com/problems/FCTRL2/

FCTRL2 - Small factorials

 

You are asked to calculate factorials of some small positive integers.

Input

An integer t, 1<=t<=100, denoting the number of testcases, followed by t lines, each containing a single integer n, 1<=n<=100.

Output

For each integer n given at input, display a line with the value of n!

Example

Sample input:
4
1
2
5
3

Sample output:

1
2
120
6

 

Code Examples

#1 Code Example with Java Programming

Code - Java Programming

import java.util.*;
import java.math.*;
class fctrl2
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int no=sc.nextInt();
BigInteger[] a=new BigInteger[no];
for(int i=0;i<no;i++)
{
a[i]=fact(sc.nextInt());
}
for(int i=0;i<no;i++)
{
System.out.println(a[i]);
}
}
public static BigInteger fact(long b)
{
BigInteger c= BigInteger.valueOf(1);
for(int i=1;i<=b;i++)
{
c=c.multiply(BigInteger.valueOf(i));
}
return c;
}
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
4
1
2
5
3

Output

x
+
cmd
1
2
120
6
Advertisements

Demonstration


SPOJ Solution-Small factorials-Solution in C, C++, Java, Python

Previous
SPOJ Solution - Test Life, the Universe, and Everything - Solution in C, C++, Java, Python