Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,540 --> 00:00:04,350
All right, so that's another example in our Recursions section.
2
00:00:04,770 --> 00:00:10,080
And in this video, what we are going to do is to write a function that received some natural number
3
00:00:10,200 --> 00:00:14,160
NUM and returns there, factorial of this number.
4
00:00:14,310 --> 00:00:21,630
And for those of you who is not so familiar with what factorial is, let's explain it in simple terms.
5
00:00:21,750 --> 00:00:30,480
So a factorial by its definition is just a mathematical operation and is defined to be as the multiplication
6
00:00:30,690 --> 00:00:34,680
of all natural numbers from one up to a given number.
7
00:00:34,860 --> 00:00:40,950
So very similar to how we used to find the sum of all the numbers from one up to number.
8
00:00:41,100 --> 00:00:47,820
The factorial simply finds the multiplication of all the numbers of all the natural numbers from one
9
00:00:47,970 --> 00:00:49,410
to a given number.
10
00:00:49,590 --> 00:00:55,890
So, for example, if we want to calculate the factorial for numskulls two three, then our recursive
11
00:00:55,890 --> 00:01:02,370
function should return the result of one multiplied by two, multiplied by three, which is a total
12
00:01:02,370 --> 00:01:03,270
of six.
13
00:01:03,420 --> 00:01:09,330
And if we want to calculate the factorial for nummy equals two five, then our recursive function should
14
00:01:09,330 --> 00:01:15,220
return the result of one multiplied by two and so on, up to five, which is a total of one hundred
15
00:01:15,220 --> 00:01:15,800
and twenty.
16
00:01:15,980 --> 00:01:22,350
So basically we can say that the function for a given NUM should return the following result of one
17
00:01:22,350 --> 00:01:25,560
multiplied by two, multiplied by three and so on.
18
00:01:25,620 --> 00:01:32,340
Up until a given num so num minus one will be our one element before the last one.
19
00:01:32,370 --> 00:01:38,280
And num will be our last element in this multiplication factorial formula.
20
00:01:38,430 --> 00:01:39,500
Not so complicated.
21
00:01:39,510 --> 00:01:39,920
Right.
22
00:01:40,170 --> 00:01:43,530
And it's basically it's pretty similar to the previous example.
23
00:01:43,530 --> 00:01:51,300
We can see that the only thing that changed between these example to the previous one is that we just
24
00:01:51,390 --> 00:01:56,040
instead of using the addition operator, we are just using their multiplication.
25
00:01:56,160 --> 00:01:58,890
So also very similar to the previous question.
26
00:01:59,490 --> 00:02:02,820
So you will be able to write the factorial function with ease.
27
00:02:03,300 --> 00:02:08,430
I suggest using the same approach as we did previously and just to show you the multiplication from
28
00:02:08,430 --> 00:02:09,390
left to right.
29
00:02:09,510 --> 00:02:13,480
So instead of taking a look at this formula from the left to the right.
30
00:02:13,510 --> 00:02:18,840
Right from one multiplied by two and so on, we will look at from right to left, which is num multiplied
31
00:02:18,840 --> 00:02:21,270
by num minus one and so on and so forth.
32
00:02:21,330 --> 00:02:23,790
You've got the idea the result will be the same.
33
00:02:23,790 --> 00:02:28,390
Would it change anything, just the order that would look at the multiplication.
34
00:02:28,450 --> 00:02:31,920
But the overall result is going to be the same.
35
00:02:32,040 --> 00:02:35,790
And now it's time for some Hanzo in our programming language.
36
00:02:36,000 --> 00:02:36,600
So let's go.
3738
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.