Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,420 --> 00:00:07,650
So we already know the logic behind this exercise because previously we already solved it by just by
2
00:00:07,650 --> 00:00:08,350
using globes.
3
00:00:08,370 --> 00:00:08,670
Right.
4
00:00:08,790 --> 00:00:14,040
And all that we have to do now is to change the structure of the loop and to use instead of a while
5
00:00:14,040 --> 00:00:14,310
loop.
6
00:00:14,340 --> 00:00:16,020
We have to use a for a loop.
7
00:00:16,170 --> 00:00:18,180
So let's create or two variables.
8
00:00:18,270 --> 00:00:19,470
The number itself.
9
00:00:19,530 --> 00:00:22,530
So int num count the power power.
10
00:00:23,110 --> 00:00:28,590
And also we need to create another variable that will hold the final result and will help us with the
11
00:00:28,590 --> 00:00:29,850
calculations in the loop.
12
00:00:30,240 --> 00:00:33,490
And this variable will be of course, the results.
13
00:00:33,740 --> 00:00:34,570
So into resolve.
14
00:00:34,830 --> 00:00:35,820
Equals two one.
15
00:00:36,090 --> 00:00:39,180
And in the previous challenge we explained why this.
16
00:00:39,770 --> 00:00:41,200
This our variable.
17
00:00:41,250 --> 00:00:42,060
This result.
18
00:00:42,400 --> 00:00:44,120
Initialize the value of ones.
19
00:00:44,240 --> 00:00:45,390
And if you don't remember.
20
00:00:45,600 --> 00:00:50,160
Go back to the previous challenge and make sure you get the whole idea behind it.
21
00:00:50,310 --> 00:00:52,860
And now let's also create the variable.
22
00:00:52,940 --> 00:00:54,030
I, i.
23
00:00:54,150 --> 00:00:57,870
So tie and this variable is required for us.
24
00:00:57,900 --> 00:01:00,430
So when we are going to use the for loop.
25
00:01:00,480 --> 00:01:06,020
So we're creating this variable that will help us using the for loop structure in C..
26
00:01:06,210 --> 00:01:06,960
All right.
27
00:01:07,020 --> 00:01:09,920
And now let's read these values from the user.
28
00:01:09,960 --> 00:01:13,680
So enter Nahm pretty much the same as we've done previously.
29
00:01:13,710 --> 00:01:14,520
Enter NARM.
30
00:01:14,550 --> 00:01:19,310
Then we are going to scan F percentage D and put it inside Nahm.
31
00:01:19,710 --> 00:01:23,730
And the same we are going to do also for the power and her power.
32
00:01:24,330 --> 00:01:30,870
I guess I'm typing a little bit faster than it would be for just copy and paste.
33
00:01:31,010 --> 00:01:32,760
And then I need to change it.
34
00:01:32,910 --> 00:01:38,130
So yeah, I think it is even better and actually it's more safe.
35
00:01:38,220 --> 00:01:40,620
So we are using it in this way.
36
00:01:40,650 --> 00:01:42,250
We are reading the first number.
37
00:01:42,320 --> 00:01:43,740
Then we are reading the power.
38
00:01:44,130 --> 00:01:48,970
And now what we are going to do is to get down to our loop.
39
00:01:49,110 --> 00:01:52,650
And the first thing that you have to do is write the for a statement.
40
00:01:52,770 --> 00:01:58,110
Then you are going to specify there are the initialization of the variable.
41
00:01:58,170 --> 00:01:59,580
I will write this.
42
00:02:00,000 --> 00:02:00,420
This.
43
00:02:00,540 --> 00:02:02,080
Let's put it to be.
44
00:02:02,280 --> 00:02:03,160
I equals to one.
45
00:02:03,200 --> 00:02:08,700
These line these command will be executed only once when we reach this line.
46
00:02:08,790 --> 00:02:11,100
The line fifteen for the first time.
47
00:02:11,610 --> 00:02:15,340
This line will not be executed every time on every duration.
48
00:02:15,370 --> 00:02:15,750
All right.
49
00:02:15,810 --> 00:02:16,860
Only the first time.
50
00:02:16,890 --> 00:02:20,910
This is the initialization section of these for a loop.
51
00:02:21,060 --> 00:02:23,640
So we initially want to be equals to one.
52
00:02:24,120 --> 00:02:31,070
And then we are going to specify, let's specify the condition until when we are going to execute this
53
00:02:31,070 --> 00:02:31,470
loop.
54
00:02:31,500 --> 00:02:38,040
So until we reach I is less than or equal as to the power.
55
00:02:38,370 --> 00:02:44,940
And every time on every duration, every time when every iteration, we are going to increment I by
56
00:02:44,940 --> 00:02:45,330
one.
57
00:02:45,450 --> 00:02:49,800
So the same way as we've done previously with the wire loops, just that.
58
00:02:49,860 --> 00:02:53,140
Now we are writing in for a loop structure.
59
00:02:53,160 --> 00:02:55,410
So here is the first thing you channelization.
60
00:02:55,860 --> 00:03:01,620
This line will be executed on every end of every duration.
61
00:03:01,640 --> 00:03:04,600
So we are going to execute, first of all, the loop body.
62
00:03:04,620 --> 00:03:07,740
Here is going to be the loop body once it's executed.
63
00:03:07,950 --> 00:03:09,690
You are going to run this command.
64
00:03:09,930 --> 00:03:17,130
And if you want to execute the loop body on every duration before you enter the loop, buddy, you are
65
00:03:17,130 --> 00:03:21,720
going to make sure that this condition is satisfied and the result of it is true.
66
00:03:21,750 --> 00:03:30,000
So as long as I as long as I is less than the power entered by the user, we are going to execute this
67
00:03:30,000 --> 00:03:30,870
loop body.
68
00:03:30,990 --> 00:03:34,440
And then the loop body itself is going to be pretty straightforward.
69
00:03:34,470 --> 00:03:36,390
We are just going to use result.
70
00:03:36,450 --> 00:03:37,560
Equals the result.
71
00:03:37,680 --> 00:03:39,120
This is the previous result.
72
00:03:39,330 --> 00:03:41,670
This is the new result that we are going to receive.
73
00:03:41,910 --> 00:03:44,670
So the previous result multiplied by NUM.
74
00:03:44,700 --> 00:03:45,000
Right.
75
00:03:45,030 --> 00:03:51,720
Every time we multiply num by num, multiplied by Nahm and so on and we keep the current result.
76
00:03:52,110 --> 00:03:56,430
And then we multiply the current result by now to get a new updated result.
77
00:03:56,550 --> 00:04:00,420
That's how the power mathematical function works.
78
00:04:00,540 --> 00:04:07,470
So on each iteration, on each iteration, we are going to multiplied, then increase the UI by one
79
00:04:07,640 --> 00:04:07,920
check.
80
00:04:08,040 --> 00:04:09,660
That the condition is satisfied.
81
00:04:09,810 --> 00:04:16,830
And then run the look body once again until we reach some time that these condition happens to be false.
82
00:04:16,950 --> 00:04:17,550
All right.
83
00:04:17,560 --> 00:04:23,520
So now all that we have to do is once we get out of this slope, is just to bring the result in, just
84
00:04:23,520 --> 00:04:24,960
like we did it previously.
85
00:04:24,990 --> 00:04:27,930
Let's use something like this printout percentage.
86
00:04:27,930 --> 00:04:28,160
The.
87
00:04:28,350 --> 00:04:30,630
This is the number in the power.
88
00:04:30,900 --> 00:04:31,980
In the power.
89
00:04:32,100 --> 00:04:32,400
Right.
90
00:04:32,430 --> 00:04:37,480
It was something like this off percentage, the equals to percentage, Dean.
91
00:04:37,590 --> 00:04:40,440
And that's actually what the calculator is given you.
92
00:04:40,920 --> 00:04:47,160
Just not reading like this is percentage D and the power of percent the G equals to the result itself.
93
00:04:47,430 --> 00:04:54,350
And here we are going to specify the values that are going to be placed instead of these percentage
94
00:04:54,360 --> 00:04:54,740
D.
95
00:04:54,750 --> 00:04:55,070
Right.
96
00:04:55,500 --> 00:04:57,060
Instead of these place holders.
97
00:04:57,170 --> 00:04:59,090
So first of all, comes the NUM.
98
00:04:59,130 --> 00:04:59,580
Then we.
99
00:05:00,270 --> 00:05:06,310
All and then we have the result of them, which is held in the result variable.
100
00:05:06,430 --> 00:05:07,130
And there you go.
101
00:05:07,300 --> 00:05:10,180
You can build an Bromley's program to make sure that it works.
102
00:05:10,570 --> 00:05:11,470
So let's do it.
103
00:05:11,500 --> 00:05:13,360
Let's save it and build and run it.
104
00:05:13,510 --> 00:05:15,940
Oh, hey, here we go.
105
00:05:16,420 --> 00:05:16,750
Oh.
106
00:05:16,840 --> 00:05:18,280
So here we have an error.
107
00:05:18,370 --> 00:05:19,930
Let's see what it what it says.
108
00:05:19,960 --> 00:05:20,980
Let's see what it says.
109
00:05:21,100 --> 00:05:27,820
And you can see here, if you take a closer look at that in line fifteen, we are trying to use Pough
110
00:05:27,830 --> 00:05:30,220
variable, which is undeclared.
111
00:05:30,610 --> 00:05:31,840
Why is it undeclared?
112
00:05:32,200 --> 00:05:35,350
Oh, because we defined it as power and not power.
113
00:05:35,380 --> 00:05:39,130
So let's just modified to be something like that.
114
00:05:39,460 --> 00:05:39,730
OK.
115
00:05:39,790 --> 00:05:41,870
So now we have Bao Bao Bao.
116
00:05:41,890 --> 00:05:43,660
Previously we used power.
117
00:05:44,110 --> 00:05:46,420
If we used here power, we didn't specify.
118
00:05:46,420 --> 00:05:51,910
We didn't declare this variable nowhere because it was just power.
119
00:05:51,940 --> 00:05:53,950
And it's a totally different variable.
120
00:05:53,950 --> 00:05:54,240
Right.
121
00:05:54,280 --> 00:05:59,050
It's sname it's not the same and totally the compiler does not understand what we want.
122
00:05:59,230 --> 00:06:02,310
So now let's try to run, build and run it.
123
00:06:03,490 --> 00:06:07,110
So build and run and let's make our previous examples.
124
00:06:07,110 --> 00:06:10,450
So two in the power of three should give us eight.
125
00:06:10,510 --> 00:06:11,950
So let's press answering.
126
00:06:11,970 --> 00:06:14,440
Two in the power of three gives us eight.
127
00:06:14,860 --> 00:06:21,150
And also we can make sure that five in the power of five in the power of five.
128
00:06:21,190 --> 00:06:21,880
Let's see.
129
00:06:22,090 --> 00:06:22,870
It should be.
130
00:06:23,290 --> 00:06:25,030
Yeah, it should be something like that.
131
00:06:25,990 --> 00:06:28,590
So this is it for these video guys.
132
00:06:28,780 --> 00:06:34,540
And the whole point was just to show you that we can solve the same task, find the numbering the Bowery
133
00:06:34,630 --> 00:06:36,130
are given.
134
00:06:36,190 --> 00:06:37,660
Given a numbering in its power.
135
00:06:37,660 --> 00:06:42,550
We can solve it in two different ways, using the while loops or the four loops.
136
00:06:42,700 --> 00:06:48,640
Both of them solve this exercise, but you should go with just one of them in this case.
137
00:06:48,700 --> 00:06:50,380
In this type of challenges.
138
00:06:50,500 --> 00:06:52,450
And which one of them should it be?
11340
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.