Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,240 --> 00:00:06,120
What is going on, guys, and welcome to our first example that we are doing and these recursions section
2
00:00:06,410 --> 00:00:11,670
of this video, in this example, we are going to write a function, a recursive function that will
3
00:00:11,670 --> 00:00:19,050
receive some naturale number, which is numb, and then it will return the sum of the arithmetical progression
4
00:00:19,050 --> 00:00:21,170
from one up to number.
5
00:00:21,390 --> 00:00:28,650
So we are going to write a recursive function that will call itself and once it calls itself, it will
6
00:00:28,740 --> 00:00:29,430
divide.
7
00:00:29,520 --> 00:00:35,540
The main problem into some sub smaller sub problems until it reaches some stopping condition.
8
00:00:35,820 --> 00:00:41,000
And the result will be to find the sum from one up to number.
9
00:00:41,160 --> 00:00:47,280
So, for example, if we received anomic Wil's two three, then our recursive function should return
10
00:00:47,280 --> 00:00:51,120
the sum of one plus two plus three, which is a total of six.
11
00:00:51,270 --> 00:00:57,690
And if we received Nomic was two five, then our recursive function should return the sum of one plus
12
00:00:57,690 --> 00:01:02,280
still plus three plus four plus five, which is a total of fifteen.
13
00:01:02,500 --> 00:01:09,000
So as we can see, the sum of all the numbers from one up to number five for all their natural numbers
14
00:01:09,000 --> 00:01:10,020
from one to NUM.
15
00:01:10,410 --> 00:01:13,890
So that's what we want to do in this exercise, in this example.
16
00:01:14,160 --> 00:01:19,710
And we know that it can be done easily just by using some for a loop or while loop.
17
00:01:19,730 --> 00:01:19,960
Right.
18
00:01:20,280 --> 00:01:28,740
But we are going to use our new concept, our recursion concept, to solve this exercise and to make
19
00:01:28,740 --> 00:01:31,020
things a little bit easier for us.
20
00:01:31,050 --> 00:01:33,870
I suggest to write or some is the following way.
21
00:01:34,170 --> 00:01:42,300
One plus two plus three on so on up until you sum num minus one and the num itself to your general sum.
22
00:01:42,360 --> 00:01:42,630
Okay.
23
00:01:42,810 --> 00:01:48,900
And instead of looking at these sum in this way, it's just a hint that you may also look at the sum
24
00:01:48,990 --> 00:01:51,360
in the following way, which is pretty much the same.
25
00:01:51,360 --> 00:01:51,630
Right.
26
00:01:51,660 --> 00:01:55,890
It doesn't matter if you some from left to right or from right to left.
27
00:01:55,950 --> 00:01:58,080
The sum is going to be the same.
28
00:01:58,410 --> 00:02:04,860
But that's the first hint that I give you to solve this example and take a few moments to think about
29
00:02:04,860 --> 00:02:05,820
how you would do it.
30
00:02:06,120 --> 00:02:08,190
And we are going to solve it together.
31
00:02:08,400 --> 00:02:09,270
So let's go.
3100
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.