Company: Phillips, Microsoft, MAQ-Software, MakeMyTrip, BrowserStack
Question: Given an integer, the task is to find factorial of the number.
Input:
The first line of input contains an integer T denoting the number of test cases.
The first line of each test case is N,the number whose factorial is to be found
Output:
Print the factorial of the number in separate line.
Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 1000
Example:
Input
3
5
10
2
Output
120
3628800
2
Question: Given an integer, the task is to find factorial of the number.
Input:
The first line of input contains an integer T denoting the number of test cases.
The first line of each test case is N,the number whose factorial is to be found
Output:
Print the factorial of the number in separate line.
Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 1000
Example:
Input
3
5
10
2
Output
120
3628800
2
CODE:
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.BigInteger;
class Solution {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
for(int mi=0;mi<m;mi++){
int n = sc.nextInt();
BigInteger fact= new BigInteger("1");
for(int i=1;i<n+1;i++){
fact= fact.multiply(BigInteger.valueOf(i));
}
System.out.println(fact);
}
}
}
EXECUTION TIME: 0.24s
Comments
Post a Comment