Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,570 --> 00:00:07,350
All right, what is going on and in this video, we are going to solve additional new exercise regarding
2
00:00:07,350 --> 00:00:12,110
functions and basically to make some mathematical operations and so on.
3
00:00:13,470 --> 00:00:20,490
And what I want us to do is simply to write a function that receives some number, let's say function,
4
00:00:20,490 --> 00:00:26,500
receives some number, and this number will be called it in a length.
5
00:00:26,520 --> 00:00:27,080
All right.
6
00:00:28,110 --> 00:00:36,280
And what the function should do is to make some mathematical operations, some mathematical magic that
7
00:00:36,300 --> 00:00:44,280
right after these magic or the body of the function has been executed, the function is going how to
8
00:00:44,280 --> 00:00:47,530
calculate and to return the number.
9
00:00:47,580 --> 00:00:50,010
OK, the number, the following number.
10
00:00:50,010 --> 00:00:57,060
So nine nine nine until nine, right off the given length.
11
00:00:57,480 --> 00:01:00,610
So I think an example is much clearer.
12
00:01:00,630 --> 00:01:04,690
So if length is, let's make point to examples.
13
00:01:04,710 --> 00:01:13,600
So if length length is going to be like three, then the return value should be nine nine nine.
14
00:01:13,650 --> 00:01:14,110
OK.
15
00:01:15,000 --> 00:01:26,520
And if the length was like length equals to five, then the result is going to be like five times nine
16
00:01:26,520 --> 00:01:30,780
to ninety nine thousand nine hundred ninety nine.
17
00:01:30,990 --> 00:01:31,320
OK.
18
00:01:32,220 --> 00:01:37,100
So I hope the instructions are clear and let's dive into coding.
19
00:01:37,110 --> 00:01:44,550
OK, but first of all, think about the solution and do things that you have to bear in mind is basically
20
00:01:45,030 --> 00:01:48,000
I want you to think of them by yourself right now.
21
00:01:48,000 --> 00:01:52,140
These are, first of all, what is the process of working?
22
00:01:52,140 --> 00:01:53,290
How will you work?
23
00:01:53,310 --> 00:01:57,410
It's not like you have just to print the values, right.
24
00:01:57,420 --> 00:02:00,450
You have to return to return.
25
00:02:00,480 --> 00:02:06,980
OK, if it was like only to print this number to the screen, then there will be no problems at all.
26
00:02:06,990 --> 00:02:07,280
Right.
27
00:02:07,300 --> 00:02:13,950
You simply would go like using some lube and you would like just print all the values.
28
00:02:15,300 --> 00:02:20,360
You would just print nine is just length times.
29
00:02:20,370 --> 00:02:27,870
OK, so it will be like a simple for loop from a equals to one as long as as less or equal length simply
30
00:02:27,870 --> 00:02:31,070
print F nine and so on until you're done.
31
00:02:32,250 --> 00:02:34,350
But that's not something that we want.
32
00:02:34,350 --> 00:02:41,730
We want to calculate this number, maybe to hold it also in some variable and finally to return it.
33
00:02:41,760 --> 00:02:44,230
OK, so the function is going to return.
34
00:02:45,150 --> 00:02:53,310
So let's start writing the structure of the function and basically think about is is there any limitation
35
00:02:53,310 --> 00:02:56,730
that you would like to like to care to take care of?
36
00:02:56,730 --> 00:03:05,490
Maybe some type, because that may also be a problem for the signature of the function.
37
00:03:06,630 --> 00:03:09,810
But we are going to discuss about it at the end of this video.
38
00:03:09,810 --> 00:03:17,180
First of all, let's just write down the most trivial way, the most trivial signature.
39
00:03:17,190 --> 00:03:18,780
So the signature will look like this.
40
00:03:18,780 --> 00:03:23,690
So it's OK because we are going to return probably an integer.
41
00:03:23,850 --> 00:03:32,070
That's something we are going to discuss, as we just said, and let's call it nine number, OK, nine
42
00:03:32,070 --> 00:03:37,850
number of these function will create and a number based on the length of the sequence is going to receive.
43
00:03:38,460 --> 00:03:39,020
Awesome.
44
00:03:39,030 --> 00:03:40,890
So that's the signature of the function.
45
00:03:41,310 --> 00:03:46,680
And basically, how should you treat and how we should you solve this question?
46
00:03:47,700 --> 00:03:53,130
First of all, we need to understand that we need to create some new number.
47
00:03:53,150 --> 00:03:58,670
So let's assume that we will make some I don't know, ain't nothing, OK?
48
00:03:59,010 --> 00:04:02,310
And this thing now will be used for our calculation.
49
00:04:02,970 --> 00:04:11,280
And what we are going to do is simply to understand that at every phase, OK, off some loop that we
50
00:04:11,280 --> 00:04:15,080
are going to use in the help of this, ain't I?
51
00:04:15,570 --> 00:04:22,380
So we will use some loop and we'll start this loop from I equals to, let's say I don't know, zero
52
00:04:22,380 --> 00:04:24,710
up until I use less than length.
53
00:04:24,870 --> 00:04:32,610
OK, I plus plus and what we are going to do in the body of the loop is basically every time.
54
00:04:32,670 --> 00:04:36,630
OK, so let's just set now to be zero at the beginning.
55
00:04:36,990 --> 00:04:41,820
What we would like to do is the following so now equals to zero.
56
00:04:42,570 --> 00:04:49,680
And in the first iteration we would like num to be equals to, to be equal to what should be equal to
57
00:04:49,860 --> 00:04:50,460
do nine.
58
00:04:50,880 --> 00:04:55,800
OK, the second iteration number should be equal to 999.
59
00:04:55,980 --> 00:04:56,330
Right.
60
00:04:56,340 --> 00:04:57,450
That's what we want to achieve.
61
00:04:57,750 --> 00:05:02,440
But how these 999 can be achieved, it can be achieved as the following.
62
00:05:02,460 --> 00:05:06,660
OK, it can be achieved by multiplying the previous NUM by ten.
63
00:05:06,660 --> 00:05:10,170
So it will be like now multiplied by ten plus nine.
64
00:05:10,830 --> 00:05:15,780
OK, so it will be a total of ninety nine.
65
00:05:18,380 --> 00:05:24,680
And then in the next iteration, we are going to use pretty much the same number multiplied by 10,
66
00:05:25,140 --> 00:05:31,310
just that now now equals to ninety nine, the previous value of none plus nine.
67
00:05:31,700 --> 00:05:38,720
So this will give us nine hundred and ninety plus nine, which is nine nine nine three times.
68
00:05:38,730 --> 00:05:42,710
OK, so that's the first iteration, the second, the third and so on.
69
00:05:42,890 --> 00:05:44,840
Up until up until what.
70
00:05:44,840 --> 00:05:48,380
Up until you get you finish this length.
71
00:05:48,800 --> 00:05:49,490
All right guys.
72
00:05:49,820 --> 00:05:51,090
Is that clear so far.
73
00:05:51,860 --> 00:05:52,380
Awesome.
74
00:05:52,850 --> 00:06:00,370
So what we have to do right now is simply to utilize the body of these for a loop.
75
00:06:00,710 --> 00:06:05,310
And what do you think what do you think should be the body here?
76
00:06:06,410 --> 00:06:07,010
Take a moment.
77
00:06:07,010 --> 00:06:07,850
Think about it.
78
00:06:08,270 --> 00:06:08,570
Right.
79
00:06:08,570 --> 00:06:15,890
Because we've written all the structure, all the values, all the information is already right in front
80
00:06:15,890 --> 00:06:16,240
of you.
81
00:06:16,970 --> 00:06:18,700
So look at this.
82
00:06:18,710 --> 00:06:23,570
Try to come up with some solution, with some idea.
83
00:06:23,600 --> 00:06:26,900
OK, try try try to make something out of this.
84
00:06:28,230 --> 00:06:36,610
And what we are going to do now is basically to construct some formula and this formula says the following.
85
00:06:37,200 --> 00:06:40,880
So at every duration we will take to calculate.
86
00:06:40,890 --> 00:06:49,650
Now we will take the previous now the previous value of now multiplied by 10 and add a nine to it,
87
00:06:50,610 --> 00:06:56,060
which is also will work because on the first the duration when we say now equals to nine.
88
00:06:56,100 --> 00:07:04,710
That's not entirely related to the formula, but rather we can also represent it is now multiplied by
89
00:07:04,710 --> 00:07:05,900
ten plus nine.
90
00:07:05,910 --> 00:07:06,240
Right.
91
00:07:06,600 --> 00:07:13,080
And we know that the previous number, the number we set up here to be zero zero zero multiplied by
92
00:07:13,080 --> 00:07:15,090
ten is zero plus nine is nine.
93
00:07:15,310 --> 00:07:17,820
OK, so that's the result from here.
94
00:07:18,060 --> 00:07:19,970
And then we go to the next iteration.
95
00:07:19,980 --> 00:07:25,530
So to calculate the next next then we calculate now we will take the previous number, which is nine
96
00:07:25,530 --> 00:07:31,080
multiplied by ten, which is 90 plus nine, which is ninety nine and so on and so forth.
97
00:07:31,200 --> 00:07:38,670
Up until you do this operation length time and you will receive this number, this sequence of nine
98
00:07:38,670 --> 00:07:41,030
nine nine length times.
99
00:07:41,200 --> 00:07:41,680
All right.
100
00:07:42,660 --> 00:07:50,430
So to put it simple, in our code, we will say that number equals to the previous Naameh.
101
00:07:50,430 --> 00:07:52,290
Multiplied by what?
102
00:07:52,740 --> 00:07:56,220
Multiplied by ten plus nine.
103
00:07:56,910 --> 00:07:57,530
All right.
104
00:07:58,830 --> 00:08:06,150
So that's basically all there is to it just to calculate this value.
105
00:08:07,320 --> 00:08:17,910
OK, so now once we know that this the this solution is pretty much legit, let's also return this sequence.
106
00:08:18,310 --> 00:08:21,350
There's no return on this now.
107
00:08:21,390 --> 00:08:24,790
Sequence a sequence of nines.
108
00:08:24,920 --> 00:08:26,250
OK, so nine.
109
00:08:26,250 --> 00:08:26,820
No.
110
00:08:28,840 --> 00:08:29,440
Awesome.
111
00:08:29,470 --> 00:08:32,130
And now let's also go down in here.
112
00:08:32,200 --> 00:08:34,500
I don't know, prenda a nice message.
113
00:08:34,520 --> 00:08:40,570
Let's just what we want to do now is to test the these nine number of function works as expected.
114
00:08:40,570 --> 00:08:54,820
So for them to have either please enter or length for the ninth sequence sequence.
115
00:08:55,250 --> 00:08:55,680
Right.
116
00:08:56,110 --> 00:09:04,750
We are going to read this value from the user and store it inside some variable it's created and length
117
00:09:05,830 --> 00:09:06,660
sequence.
118
00:09:06,740 --> 00:09:13,990
OK, and then we will read really second half percentage, the entire length sequence.
119
00:09:15,010 --> 00:09:19,940
And now what we are going to do is just basically to call these functions.
120
00:09:19,960 --> 00:09:29,200
So also let's create some identity and result and we will do like a result equals two nine number nine,
121
00:09:29,390 --> 00:09:33,850
number four length sequence.
122
00:09:34,480 --> 00:09:35,030
All right.
123
00:09:35,470 --> 00:09:40,390
And these results should also should basically hold the nine nine, nine length times.
124
00:09:40,840 --> 00:09:42,230
So that's primitive.
125
00:09:42,580 --> 00:09:49,160
The result equals to percentage the resolution and here will specify result.
126
00:09:50,110 --> 00:09:50,690
Great.
127
00:09:50,950 --> 00:09:55,510
So now what we have to do is just to run these programs.
128
00:09:55,510 --> 00:09:59,920
So let's build and run it and make sure everything works as expected.
129
00:09:59,950 --> 00:10:01,330
So let me give it here.
130
00:10:01,330 --> 00:10:02,640
So hi there.
131
00:10:02,650 --> 00:10:06,490
Please enter blank for the night and sequence.
132
00:10:06,500 --> 00:10:12,730
It was it was supposed to be 9th, so let's make it five and there we go.
133
00:10:12,730 --> 00:10:15,880
Result equals two nine nine nine five times.
134
00:10:17,120 --> 00:10:17,620
Awesome.
135
00:10:18,100 --> 00:10:20,770
Let's make sure that it works also.
136
00:10:20,800 --> 00:10:22,810
OK, so let's hear it.
137
00:10:22,820 --> 00:10:25,870
Another three also works fine.
138
00:10:26,380 --> 00:10:26,950
Great.
139
00:10:27,460 --> 00:10:29,020
Seems to be working correctly.
140
00:10:30,760 --> 00:10:37,930
But now just before you're about to celebrate that everything works as expected, I want to take care
141
00:10:37,930 --> 00:10:39,610
of two things.
142
00:10:40,070 --> 00:10:45,760
The first thing that we need to take care of is just the ending condition.
143
00:10:46,000 --> 00:10:55,420
And we need to like to understand that this problem will not go that smooth if length will be like a
144
00:10:55,420 --> 00:10:56,370
negative number.
145
00:10:56,380 --> 00:11:04,390
OK, so maybe a good idea would be to add here also some message and to say if length is less than or
146
00:11:04,390 --> 00:11:09,190
equal to zero, then in this case bring some descriptive message to the user.
147
00:11:10,150 --> 00:11:17,680
And another thing that we need to take care of, which is also very important, is the fact that let's
148
00:11:17,680 --> 00:11:19,540
try to build and run it and see what happens.
149
00:11:19,570 --> 00:11:21,090
So let's go like this.
150
00:11:21,130 --> 00:11:26,140
So we said that if we enter here five, we will get nine nine nine nine nine.
151
00:11:26,860 --> 00:11:30,510
And if we will do it like four seven, it will be seven times nine.
152
00:11:30,880 --> 00:11:32,900
But what will happen if we enter here?
153
00:11:32,950 --> 00:11:37,030
Thirty one, do you think will be printed to the screen.
154
00:11:38,790 --> 00:11:41,370
So let's run it and see what happens.
155
00:11:41,950 --> 00:11:47,410
OK, so that's very, very strange, very strange.
156
00:11:47,790 --> 00:11:54,810
So let's build it around it once again and see what happens if we enter even, I don't know, 15.
157
00:11:55,780 --> 00:11:56,960
Negative number.
158
00:11:57,130 --> 00:11:59,910
What's going on here, guys, what's going on?
159
00:11:59,920 --> 00:12:02,200
Let's also add, I don't know, 10.
160
00:12:03,210 --> 00:12:06,650
Very strange, why, why, why is that what's happening?
161
00:12:07,290 --> 00:12:13,190
So let's see also for eight, but for eight, which looks OK, so what's the problem?
162
00:12:13,200 --> 00:12:15,810
Where, where, where?
163
00:12:15,810 --> 00:12:24,140
It basically starts to like to do not work correctly and to give us some arbitrary numbers.
164
00:12:24,270 --> 00:12:25,080
What do you think?
165
00:12:27,210 --> 00:12:29,460
And that's that's quite a problem.
166
00:12:30,240 --> 00:12:37,200
So what I suggest you to do is basically to understand the concept of using integers.
167
00:12:37,830 --> 00:12:47,220
And we know that the jurors are basically just data types that are used to hold different values of
168
00:12:47,220 --> 00:12:50,510
an integer type in our C programming language.
169
00:12:51,420 --> 00:13:00,300
But the problem is that these variables, they are also kind of limited in terms of what values they
170
00:13:00,300 --> 00:13:07,140
can store, because we remember that a typical integer is just four bytes of memory.
171
00:13:07,200 --> 00:13:07,620
Right?
172
00:13:08,010 --> 00:13:09,800
It's just four bytes of memory.
173
00:13:10,230 --> 00:13:13,640
And since we know it, it's kind of four bytes.
174
00:13:13,650 --> 00:13:19,170
We know that there is some limitation on the value that it can that it can store.
175
00:13:19,390 --> 00:13:27,900
OK, so there are there is some range of values that an ancient integer number can store.
176
00:13:28,740 --> 00:13:37,410
And this value lies between, if I'm not mistaken, from about minus two million up to two million or
177
00:13:37,410 --> 00:13:38,900
three billion.
178
00:13:38,910 --> 00:13:39,480
What was it?
179
00:13:39,630 --> 00:13:46,750
I think billion from from like nine to nine to ten digits numbers.
180
00:13:46,770 --> 00:13:53,850
OK, so that's basically the range that on an integer variable can store.
181
00:13:54,390 --> 00:14:03,690
And if you're going like to specify to specify 30, 30 digits that you want to print.
182
00:14:03,690 --> 00:14:03,900
Right.
183
00:14:03,900 --> 00:14:09,720
These nine nine nine nine that you want to do like this nine nine nine nine nine that you want to get
184
00:14:09,720 --> 00:14:18,990
like 30, for example, digits in a number, then our variable will not be able to do this task and
185
00:14:18,990 --> 00:14:21,870
some information will not be displayed correctly.
186
00:14:23,030 --> 00:14:31,850
So if you would like to handle it even better, there are, of course, better variable data types,
187
00:14:31,850 --> 00:14:41,270
for example, like first of all, using longer, OK, longer is a data type for storing eight bytes
188
00:14:41,270 --> 00:14:43,240
of values.
189
00:14:44,180 --> 00:14:46,380
It will be a better choice here.
190
00:14:46,400 --> 00:14:51,270
So simply, you will need change like this into longer than just the printing also.
191
00:14:51,830 --> 00:14:54,080
And basically you will be able to store I don't know.
192
00:14:54,080 --> 00:15:00,380
I don't remember exactly how much, but I think it's about 20, 20 digits, something like that.
193
00:15:00,470 --> 00:15:02,060
But I don't remember exactly.
194
00:15:02,720 --> 00:15:06,050
You also may check it out, of course, in the documentation.
195
00:15:06,740 --> 00:15:15,110
And another way, that's not something I think we will cover up in these course is to use some conversion
196
00:15:15,110 --> 00:15:16,010
mechanism.
197
00:15:16,280 --> 00:15:18,990
That's a question that he's being asked the lot in.
198
00:15:19,550 --> 00:15:26,930
At least I remember he has been asked a lot in interviews, questions and needs regarding how you can
199
00:15:26,930 --> 00:15:29,210
represent a given number.
200
00:15:29,540 --> 00:15:33,650
OK, with kind of no no limitations.
201
00:15:33,920 --> 00:15:34,370
All right.
202
00:15:34,380 --> 00:15:40,610
So the process will be like to there will be there will be, of course, limitations, but there will
203
00:15:40,610 --> 00:15:50,900
be like really, really major, because you should take a value of an integer, some number and basically
204
00:15:50,900 --> 00:15:53,990
to convert it to and from a string.
205
00:15:54,230 --> 00:16:00,680
And then, you know, the string can have multiple characters, much more than just one variable of
206
00:16:00,680 --> 00:16:03,050
an integer, a double or a float can hold.
207
00:16:03,610 --> 00:16:05,960
And basically that's how you're going to work.
208
00:16:05,960 --> 00:16:09,650
But that's a totally different function, a total different functionality.
209
00:16:10,010 --> 00:16:11,300
That's not for this video.
210
00:16:11,300 --> 00:16:19,220
But that's very important for me to give to you as a bonus and as an understanding for the whole process.
211
00:16:21,350 --> 00:16:29,470
Oh, so I think this video was not an easy one, it was a good one with a lot of very valuable information.
212
00:16:29,930 --> 00:16:32,640
So as always, guys, thank you so much for watching.
213
00:16:32,930 --> 00:16:34,670
Let me know in the comments.
214
00:16:34,790 --> 00:16:41,380
Give me some review that I will know that my videos are helping or helping you.
215
00:16:41,840 --> 00:16:43,890
And yeah, this is it.
216
00:16:44,060 --> 00:16:44,670
Thank you.
217
00:16:44,690 --> 00:16:46,410
My name is Vlad Alphatech.
218
00:16:46,430 --> 00:16:46,970
Goodbye.
20557
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.