Consider if ‘N’ = 4, the Factorial of 4 will be the product of all numbers from 1 to 4, which is 1 * 2 * 3 * 4 = 24. Hence, the answer is 24.
The first line of the input contains an integer, 'T,’ denoting the number of test cases.
The first and only line of each test case contains one single integer ‘N’ representing the given integer.
For each test case, print the value of factorial of ‘N’.
Print the output of each test case in a separate line.
1 <= T <= 10
1 <= N <= 100
Time limit: 1 sec
In this approach, we will calculate the factorial of the given number and store it in the form of a Linked List of digits named digits. To do this, we will define a function multiply(digits,x) that will multiply the number corresponding to the digits with x and update the digits with the product’s value. Then we will initialize the linked list digits with 1 and multiply it with all numbers from 2 to N using the multiply function. At last, we will print the list in reverse order.
In this approach, we will calculate the factorial of the given number and store it in the form of an array of digits named digits. To do this, we will define a function multiply(digits, x) that will multiply the number corresponding to the digits array with x and update the digits array with the product’s value.
We will initialize the digits array with 1 and multiply it with all numbers from 2 to N using the multiply function. At last, we will print the digits array.