All language subtitles for 2. Why using loops

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian Download
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,180 --> 00:00:00,940 Welcome back. 2 00:00:00,960 --> 00:00:02,300 Alphatech Practice service. 3 00:00:02,370 --> 00:00:06,550 And before we move on, I want to tell you congratulations. 4 00:00:06,920 --> 00:00:12,360 If you made it so far out of these chorus, it means you are on the right path to becoming a better 5 00:00:12,450 --> 00:00:16,680 a much better programmer, as I guess you've probably noticed by now. 6 00:00:16,980 --> 00:00:22,560 Every news section that you start this course is mostly based upon previous ones. 7 00:00:22,740 --> 00:00:26,820 So everything is related and every topic you study is important. 8 00:00:26,850 --> 00:00:30,900 And it's probably going to be used in one of the next sections. 9 00:00:30,990 --> 00:00:36,870 For example, you remember variables when we studied variables and then we used them in the conditions 10 00:00:36,870 --> 00:00:43,980 section as well as using other functions like input and output throughout most of these course and most 11 00:00:43,980 --> 00:00:45,660 of these challenges so far. 12 00:00:45,780 --> 00:00:51,700 And that's a very important note, guys, that I want you to pay attention to, because you see you 13 00:00:51,700 --> 00:00:58,380 are actually not allowed to jump from one section to another or miss any of the sections, because if 14 00:00:58,380 --> 00:01:03,690 you do, you're probably not going to understand anything in the next sections. 15 00:01:03,990 --> 00:01:05,430 I mean, anything at all. 16 00:01:05,550 --> 00:01:13,320 That's why I say once again, you have to take all the challenges to try them to do them during every 17 00:01:13,320 --> 00:01:16,410 section and also once in a while. 18 00:01:16,560 --> 00:01:18,900 Make it quick refreshment of the material. 19 00:01:18,900 --> 00:01:20,070 Learn so far. 20 00:01:20,160 --> 00:01:20,490 So what? 21 00:01:20,490 --> 00:01:23,310 It will be much more effective and easier for you. 22 00:01:23,430 --> 00:01:31,170 So these are just some guidelines of what you should and what you shouldn't do to get the maximum knowledge 23 00:01:31,200 --> 00:01:33,770 and value out of these course. 24 00:01:34,200 --> 00:01:35,340 So I hope you got it. 25 00:01:35,430 --> 00:01:43,020 And now we can go back to our topic and introduce and talk about Loop's and one of the best methods 26 00:01:43,020 --> 00:01:44,640 of explaining this topic. 27 00:01:44,850 --> 00:01:51,030 I think it should be done using some project that we've started previously and we keep on developing 28 00:01:51,120 --> 00:01:52,050 as we go. 29 00:01:52,500 --> 00:01:56,910 And of course, I'm talking about a calculator milestone's we've taken previously. 30 00:01:57,330 --> 00:02:03,300 So previously it was just some basic calculator which supported just basic functionality. 31 00:02:03,300 --> 00:02:03,660 Right. 32 00:02:04,050 --> 00:02:11,430 And now I want us to start perfecting it by adding more functionality, making it more like a real calculator. 33 00:02:11,520 --> 00:02:17,880 But before we move on to do so and before any formal loop's explanations, let us take a look at this 34 00:02:18,180 --> 00:02:19,500 following example. 35 00:02:20,130 --> 00:02:25,200 Suppose that you have to write a program that gets a number as input from the user. 36 00:02:25,500 --> 00:02:33,780 For example, num of type end and then the program has to print num in the power of two and nahm in 37 00:02:33,780 --> 00:02:34,830 the power of three. 38 00:02:35,040 --> 00:02:41,460 So at this point you should already be able to solve these types of questions just with ease. 39 00:02:41,470 --> 00:02:41,790 Right. 40 00:02:41,970 --> 00:02:45,300 And you can give it a try on your ROEN before we proceed. 41 00:02:45,570 --> 00:02:50,340 But we are going to take a quick look and see the way we solve it. 42 00:02:50,760 --> 00:02:52,680 We solve these questions together. 43 00:02:52,770 --> 00:02:59,280 So first of all, we need to include the standard input output, create the main function, and then 44 00:02:59,280 --> 00:03:02,570 we will declare a variable called NUM. 45 00:03:02,800 --> 00:03:05,340 And it will be a feen integer type. 46 00:03:05,550 --> 00:03:12,460 Now let's print a message to the screen to let the user know that we are waiting for him to insert these 47 00:03:12,480 --> 00:03:12,980 number. 48 00:03:13,170 --> 00:03:19,120 And let's take this number that the user inserts and put it inside the num variable in. 49 00:03:19,140 --> 00:03:24,230 What we can do right now is simply to preened the result of nomine the power of two a right. 50 00:03:24,270 --> 00:03:31,370 We make these calculation of NUM multiplied by now and display the result instead of these percentages 51 00:03:31,520 --> 00:03:33,830 percentage D instead of these place holders. 52 00:03:33,870 --> 00:03:38,310 So this will be just the NUM in the power of two. 53 00:03:38,430 --> 00:03:45,870 And similarly, we can print nomine the power of three simply by multiplying num multiplied by num multiplied 54 00:03:45,870 --> 00:03:48,570 by num, which is a total of three. 55 00:03:48,630 --> 00:03:49,580 So far so good. 56 00:03:49,590 --> 00:03:49,990 Right. 57 00:03:50,190 --> 00:03:56,350 We had no problems getting some number from the user and printing its nami the power of two and now 58 00:03:56,350 --> 00:03:57,450 means the power of three. 59 00:03:57,570 --> 00:04:04,320 But since we want to make some more advanced and sophisticated calculator that should know how to calculate 60 00:04:04,380 --> 00:04:11,790 NUM in any power, not just two or three, like we can see in this example, any power that the user 61 00:04:11,790 --> 00:04:12,600 will provide. 62 00:04:12,630 --> 00:04:13,370 Not just now. 63 00:04:13,370 --> 00:04:16,410 I mean, the power of two were nomine, the power of three. 64 00:04:16,470 --> 00:04:18,570 But any power, any power. 65 00:04:18,690 --> 00:04:24,030 I mean, it makes sense that we want these type of functionality, right? 66 00:04:24,420 --> 00:04:28,680 I mean, that's that's an important functionality for our calculator. 67 00:04:28,850 --> 00:04:34,980 We want to give the user the ability to specify not only the number itself, but also the power that 68 00:04:34,980 --> 00:04:37,210 this number will be raised in. 69 00:04:37,290 --> 00:04:44,370 For example, if the user was to provide NOM equals to two and a power of six, then the result will 70 00:04:44,370 --> 00:04:48,670 be narm in the power of six was a total of 64. 71 00:04:49,260 --> 00:04:54,510 That's much better and much more functional and various application, isn't it. 72 00:04:54,630 --> 00:04:59,740 We simply provide here more options and abilities for calculation so we can see if. 73 00:04:59,870 --> 00:05:03,290 We run this program as it is right now. 74 00:05:03,320 --> 00:05:03,590 Right. 75 00:05:03,620 --> 00:05:07,550 We can see an example if we insert a number of five. 76 00:05:07,640 --> 00:05:08,000 All right. 77 00:05:08,030 --> 00:05:08,840 This is NUM. 78 00:05:09,140 --> 00:05:14,850 Then we always are going to receive just naming the square of two and naming the square three. 79 00:05:15,200 --> 00:05:15,860 And that's it. 80 00:05:16,130 --> 00:05:19,550 So let's now answer an important question. 81 00:05:19,910 --> 00:05:28,040 How can we do such a general program that we'll be able to calculate the power of any power, any number 82 00:05:28,040 --> 00:05:29,630 in any given power. 83 00:05:29,800 --> 00:05:30,090 Right. 84 00:05:30,170 --> 00:05:31,790 And added to our functionality. 85 00:05:32,150 --> 00:05:37,220 So take a minute to think about it and try to come up with a solution based on everything we've learned 86 00:05:37,220 --> 00:05:37,760 so far. 87 00:05:37,940 --> 00:05:39,170 So pause the video. 88 00:05:39,230 --> 00:05:40,820 Try to think of the solution. 89 00:05:41,000 --> 00:05:45,500 Write down your code and check if it works on your computer. 90 00:05:45,800 --> 00:05:54,020 And once you're finished, we are going to go over it together here in our nice visual viz. screen. 91 00:05:54,290 --> 00:05:59,060 So now I hope that you tried this exercise on your own. 92 00:05:59,060 --> 00:06:00,860 If not, pause the video right now. 93 00:06:00,950 --> 00:06:07,610 It's so important to try tackling these things that you don't really know for sure how to solve them. 94 00:06:07,910 --> 00:06:17,540 It's so important because when when you become a programmer, it's probably what you are going to face 95 00:06:17,570 --> 00:06:21,320 most of your career, things that you're not sure how to solve. 96 00:06:21,740 --> 00:06:25,850 And this is a good start to begin with. 97 00:06:26,130 --> 00:06:32,930 So now let's think about the answer together and see if it's really possible to create such a program 98 00:06:32,930 --> 00:06:36,890 with the tools we were even introduced with so far. 99 00:06:37,010 --> 00:06:41,870 And first of all, what I want us to do is to write some common template for our program. 100 00:06:41,960 --> 00:06:46,400 So like previously, we defined a and numb a numb. 101 00:06:46,400 --> 00:06:47,420 We defined a numb. 102 00:06:47,990 --> 00:06:52,300 And here we are going to define two variables, num and POW. 103 00:06:52,700 --> 00:06:55,470 And these Val is going to represent the power. 104 00:06:55,580 --> 00:06:58,520 And of course, Nami is going to represent the number. 105 00:06:58,640 --> 00:07:04,550 And now we are going to print some message to the user, read the value, read the NUM. 106 00:07:04,610 --> 00:07:08,210 And now we are going to also read of the power. 107 00:07:08,240 --> 00:07:13,360 The user is going to specify which we didn't do this type of thing. 108 00:07:13,400 --> 00:07:17,450 Previously, the user was going to specify the power that he wants. 109 00:07:17,690 --> 00:07:23,150 So we are going to read this value and put it inside the power variable. 110 00:07:23,270 --> 00:07:29,120 So up to this point, I guess we all did pretty much the same thing we've just received from the user. 111 00:07:29,240 --> 00:07:31,130 The number and it's power. 112 00:07:31,760 --> 00:07:35,840 And just to let me know, guys, there is actually no building power. 113 00:07:35,900 --> 00:07:42,620 Operator in C, for example, we know that we can use an additional operator, which is a plus sign 114 00:07:42,620 --> 00:07:46,400 or maybe multiplication operator, which is a multiplication sign. 115 00:07:46,880 --> 00:07:51,470 But there is no such standard mark for a powering C. 116 00:07:51,950 --> 00:07:53,330 And please don't tell me. 117 00:07:53,360 --> 00:07:57,050 Just use the math, that H thing and so on. 118 00:07:57,500 --> 00:08:01,390 Guys who didn't learn the necessary material for this use that she had. 119 00:08:01,400 --> 00:08:03,650 So please don't try to get ahead of time. 120 00:08:03,880 --> 00:08:06,170 We will get to these topics in the future. 121 00:08:06,320 --> 00:08:06,980 Don't worry. 122 00:08:07,370 --> 00:08:13,100 For now, just use the tools we've learned so far in the course up to this point and try to solve these 123 00:08:13,100 --> 00:08:15,120 things just with these tools. 124 00:08:15,170 --> 00:08:15,510 OK. 125 00:08:15,920 --> 00:08:22,700 So we know that none in any power is simply numb, multiplied by numb, multiplied by numb. 126 00:08:22,790 --> 00:08:26,420 A total of power, minus one multiplications. 127 00:08:26,450 --> 00:08:32,150 For example, now, I mean, the power of three is simply numb, multiplied by numb, multiplied by 128 00:08:32,150 --> 00:08:32,570 now. 129 00:08:32,930 --> 00:08:33,440 All right. 130 00:08:33,560 --> 00:08:42,140 So once again, if we have numb in any power, then the result is numb, multiplied by numb power minus 131 00:08:42,140 --> 00:08:43,390 one times. 132 00:08:43,520 --> 00:08:43,820 Right. 133 00:08:43,850 --> 00:08:46,880 We repeat the multiplication process. 134 00:08:47,030 --> 00:08:49,910 Power minus one times. 135 00:08:50,360 --> 00:08:50,900 All right. 136 00:08:50,990 --> 00:08:57,380 So now we also know a little bit about math, and that shouldn't be the point where you've got stuck 137 00:08:57,500 --> 00:09:05,120 because, I mean, can't you know in advance how many times should you multiply a number that you received 138 00:09:05,120 --> 00:09:05,990 from the user? 139 00:09:06,110 --> 00:09:07,690 You can do that, right? 140 00:09:08,000 --> 00:09:10,280 You dump all of these much in advance. 141 00:09:10,700 --> 00:09:13,910 You could simply write down like we've used right here. 142 00:09:14,180 --> 00:09:20,930 You can multiply num multiplied by num, which is a num in the power of two or nomine the power three. 143 00:09:21,140 --> 00:09:28,880 But that wouldn't be the right answer because if the user specifies a power or four, what should you 144 00:09:28,880 --> 00:09:29,360 print. 145 00:09:29,600 --> 00:09:33,020 Should you print knowing the power of touring the power of three. 146 00:09:33,290 --> 00:09:35,270 That just doesn't make any sense. 147 00:09:35,390 --> 00:09:42,440 So basically what we want to have is something like this and we want to use a print F of function and 148 00:09:42,440 --> 00:09:47,950 print functionality that will be seen like this guy here. 149 00:09:48,140 --> 00:09:54,140 Right now I'm in the power of power equals two now, multiplied by now, multiplied by NOM and so on. 150 00:09:54,500 --> 00:09:56,430 PO minus one times. 151 00:09:56,450 --> 00:09:59,600 Like we can see the formula here under the right. 152 00:09:59,860 --> 00:10:00,120 Top. 153 00:10:00,260 --> 00:10:04,070 And that's not something that we can do with the tools we've learned so far. 154 00:10:04,610 --> 00:10:11,210 And this is exactly the point where we should introduce a new body called Loop's. 155 00:10:11,540 --> 00:10:18,410 You see, guys, when we want to calculate a NUM in some power, what we are actually doing is repeating 156 00:10:18,410 --> 00:10:21,530 some process of multiplication over and over again. 157 00:10:21,530 --> 00:10:21,910 Right. 158 00:10:22,400 --> 00:10:23,720 We are simply multiplying. 159 00:10:23,780 --> 00:10:29,960 Now, my name is certain amount of times and whenever there is a repetitive process or a bunch of commands 160 00:10:30,350 --> 00:10:36,620 which are being run over and over again, we should start thinking of loops as something that can help 161 00:10:36,620 --> 00:10:39,130 us with solving this task. 162 00:10:39,260 --> 00:10:44,930 So let us see the structure of loops and a couple of basic examples with the using loops in C. 163 00:10:45,410 --> 00:10:52,700 And then we will come back to the power as example to add the pole functionality to our calculator. 164 00:10:52,820 --> 00:10:53,360 All right. 165 00:10:53,840 --> 00:10:55,550 So I'll see you in the next video. 15729

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.