Skip to content

Commit 6b3677f

Browse files
authored
Adding a tutorial for dimik-factorial (#476)
* Create en.md * Update en.md * Update en.md
1 parent b0cb443 commit 6b3677f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

dimik-factorial/en.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Dimik - Factorial
2+
3+
In this problem, you will be given `T` testcases. Each line of the testcase consists of an integer `n`. We have to determine the factorial value of `n`
4+
5+
### Solution
6+
Factorial of any value n denotes finding the product of all the values starting from 1 upto n.
7+
In other words, `Factorial[n]=1*2*3*4...*(n-2)*(n-1)*n`.
8+
So we can make an efficient solution, by preprocessing all the factorials for different possible values of n and while going through the test cases,we can just print out the factorial of `n`.
9+
10+
### C++
11+
```cpp
12+
#include <bits/stdc++.h>
13+
using namespace std;
14+
int main()
15+
{
16+
int fact[16];
17+
fact[0] = 1;
18+
for (int i = 1; i <= 15; i++)
19+
{
20+
fact[i] = i * fact[i - 1];
21+
}
22+
int t;
23+
cin >> t;
24+
while (t--)
25+
{
26+
int n;
27+
cin >> n;
28+
cout << fact[n] << endl;
29+
}
30+
}
31+
```

0 commit comments

Comments
 (0)