All language subtitles for 21. Nested Loops - Print Right Angle Triangle Pattern - part 1 - Solution

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,570 --> 00:00:05,400 All right, so welcome back once again, let's just put it under here, OK? 2 00:00:05,430 --> 00:00:11,430 So in this video, what we are going to do is to solve the previous exorcized. 3 00:00:11,430 --> 00:00:17,060 The previous question that we simply have to print there right in your rectangle. 4 00:00:17,100 --> 00:00:20,400 So that has the following pattern. 5 00:00:20,410 --> 00:00:22,640 So, for example, an equals two three. 6 00:00:22,650 --> 00:00:24,870 That's the value that we receive from the user. 7 00:00:25,350 --> 00:00:28,190 In this case, we have to print these rectangles. 8 00:00:28,190 --> 00:00:30,180 So one, two, and one, two, three. 9 00:00:30,340 --> 00:00:34,230 OK, so I think the instructions are pretty clear to you guys. 10 00:00:34,770 --> 00:00:42,060 And the one main thing that we have to understand is what will be the logic and how we should use our 11 00:00:42,060 --> 00:00:45,360 C programming language to solve this exercise. 12 00:00:46,230 --> 00:00:52,710 And what I suggest you guys is to start with the following idea. 13 00:00:52,740 --> 00:00:57,240 OK, so let's start and try to do it with just using one loop. 14 00:00:57,570 --> 00:01:00,030 OK, just using one for a loop. 15 00:01:00,060 --> 00:01:06,780 So for I equals to one as long as I use less than or equal to n probably. 16 00:01:06,900 --> 00:01:08,580 Right I plus plus. 17 00:01:09,450 --> 00:01:15,240 So that's basically where a lot of students get stuck in. 18 00:01:15,240 --> 00:01:19,950 The question that comes here is what should you use in these for a loop. 19 00:01:20,490 --> 00:01:23,610 So we know that in the first, on the first line you should print one. 20 00:01:23,790 --> 00:01:28,810 On the second line you should print one, two and then the third line you should print one, two, three. 21 00:01:29,520 --> 00:01:34,320 But what how how can you express it here in the body of the loop? 22 00:01:35,130 --> 00:01:41,460 That's a difficult question because we may use print if I but in this case we will simply print one 23 00:01:41,460 --> 00:01:42,010 to three. 24 00:01:42,630 --> 00:01:47,920 We we also, I don't know, do it like until it's minus one or a minus still. 25 00:01:47,970 --> 00:01:52,360 But it will it will not solve our problem here. 26 00:01:53,100 --> 00:01:55,670 So what should you do? 27 00:01:56,430 --> 00:02:04,310 And basically my recommendation is to start thinking of additional loop of a nested loop. 28 00:02:05,040 --> 00:02:10,260 So we will simply use this the variable of the variable. 29 00:02:10,260 --> 00:02:15,180 I will use it as part of the outer loop, OK, the outer loop. 30 00:02:15,540 --> 00:02:20,880 And we will also use additional inside loop that I will explain you guys in a moment. 31 00:02:21,280 --> 00:02:22,060 Don't freak out. 32 00:02:22,090 --> 00:02:22,680 It's OK. 33 00:02:22,690 --> 00:02:23,370 Don't worry. 34 00:02:24,030 --> 00:02:29,910 We'll simply use additional loop and for at least a little bit to create a temp variable, some additional 35 00:02:29,910 --> 00:02:31,680 variable that we will call J. 36 00:02:32,550 --> 00:02:33,810 So it will look like this. 37 00:02:33,810 --> 00:02:36,690 So four J equals two. 38 00:02:36,960 --> 00:02:37,470 One. 39 00:02:37,790 --> 00:02:41,100 OK, let's say, OK, I'm just writing to some some option. 40 00:02:41,100 --> 00:02:43,140 You will tell me if that's OK or not. 41 00:02:43,890 --> 00:02:52,860 As long as J is less than or equal to and J plus plus and here will print the value of J. 42 00:02:53,370 --> 00:02:58,830 OK, so what do you think will be printed in this case to the screen. 43 00:02:59,670 --> 00:03:06,180 So let's build and run and see for first of all, let's see for ourselves what will be printed on the 44 00:03:06,180 --> 00:03:08,180 screen and then make some conclusions. 45 00:03:08,190 --> 00:03:13,950 OK, so let's insert, I don't know, three so you can see here. 46 00:03:13,950 --> 00:03:17,840 One, two, three, one, two, three and one, two, three, once again. 47 00:03:18,480 --> 00:03:26,120 So just to let you know how these nested loop works, basically we start from the outer loop with I 48 00:03:26,130 --> 00:03:33,720 equals to one and we run the body of this loop three times for equals to one. 49 00:03:33,720 --> 00:03:36,750 Four equals two two and four equals two three. 50 00:03:36,820 --> 00:03:40,590 OK, so three times we need to run the body of this loop. 51 00:03:40,590 --> 00:03:45,960 So one, two and three as long as I equals two, one, two and three. 52 00:03:46,650 --> 00:03:53,190 And then on every duration of the outer loop we will execute this for a loop. 53 00:03:53,490 --> 00:03:58,140 So we will execute this for a loop for I equals to one right. 54 00:03:58,320 --> 00:04:00,540 I equals to do and I equals to three. 55 00:04:00,990 --> 00:04:08,730 In what will happen inside of this loop, inside of this inner loop, we will also execute this print 56 00:04:08,880 --> 00:04:09,420 command. 57 00:04:09,660 --> 00:04:12,570 How many times how many times will do it. 58 00:04:12,900 --> 00:04:15,690 Three times when J equals to one. 59 00:04:15,690 --> 00:04:18,030 G equals to two equals to three. 60 00:04:18,900 --> 00:04:22,980 So that's where we print one to three for the first time. 61 00:04:22,980 --> 00:04:27,270 OK, so first iteration points one second prinsloo, third print's three. 62 00:04:27,690 --> 00:04:34,620 But we are not done because we completed just one iteration of the outer loop and now we will come here 63 00:04:34,620 --> 00:04:35,040 again. 64 00:04:35,250 --> 00:04:41,400 I will be incremented and equal to two and we will execute the body of this loop once again. 65 00:04:41,820 --> 00:04:44,910 And then the third time we will execute it once again. 66 00:04:44,910 --> 00:04:53,490 So on every duration of the outer for a loop we execute of full loop of this scenario duration with 67 00:04:53,490 --> 00:04:58,230 all the durations that print one, two, three to the screen. 68 00:04:58,680 --> 00:04:59,800 So I hope that's clear in. 69 00:04:59,870 --> 00:05:06,680 It's very important to understand this concept in once you know this much, let's start thinking about 70 00:05:06,680 --> 00:05:13,070 how we can pretend like, I don't know, let's basically just add also additional linowitz and print 71 00:05:13,070 --> 00:05:14,060 a percentage. 72 00:05:14,060 --> 00:05:18,660 And so that this way things will be even more clear to you. 73 00:05:18,930 --> 00:05:20,540 Of course, cynical and at the end. 74 00:05:21,410 --> 00:05:24,170 So let's build and run it once again and see what happens. 75 00:05:24,170 --> 00:05:28,100 Basically, what will be the shape of a pattern that we will get right now. 76 00:05:28,130 --> 00:05:28,700 So three. 77 00:05:29,270 --> 00:05:30,050 Oh, OK. 78 00:05:30,050 --> 00:05:35,150 So now you can see that you print one, two, three, one, two, three, one, two, three on every 79 00:05:35,150 --> 00:05:35,630 line. 80 00:05:35,630 --> 00:05:44,300 So every line simply represents one iteration of the outer loop in every column represents one iteration 81 00:05:44,300 --> 00:05:47,120 of the inner loop inside the outer loop. 82 00:05:47,660 --> 00:05:53,370 So for that, let's simply change these variable and to be variable, I. 83 00:05:53,720 --> 00:05:56,840 OK, and now let's build and run it. 84 00:05:56,850 --> 00:05:58,600 So this case we will see. 85 00:05:58,610 --> 00:06:01,850 Let me explain you guys everything in just a second. 86 00:06:02,300 --> 00:06:05,870 So let's here is three and there you go. 87 00:06:05,900 --> 00:06:14,090 There is your right angle, a rectangle pattern, just like we were requested and how it works basically. 88 00:06:14,100 --> 00:06:21,200 So we start with I equals to one, OK, and we come here to this loop in this little we we we assign 89 00:06:21,200 --> 00:06:23,810 the value of J to be equal to one and that's OK. 90 00:06:23,810 --> 00:06:31,400 We print one to the screen, then we increment J by one J equals two two and we ask the following question 91 00:06:31,610 --> 00:06:36,190 is two less than or equal to one is it. 92 00:06:36,590 --> 00:06:37,600 No, of course. 93 00:06:37,760 --> 00:06:42,290 So that's why we exit the inner loop and we simply print a new line. 94 00:06:43,130 --> 00:06:46,970 Once we are done printing the new line, we come here to the outer loop. 95 00:06:46,970 --> 00:06:51,020 We increment I by one and we have I equals to two. 96 00:06:51,570 --> 00:06:54,590 Then we come to the inner loop once again, J equals to one. 97 00:06:54,980 --> 00:06:58,520 So we know that J is less than or equal to two. 98 00:06:58,520 --> 00:07:01,850 In this case, that one is less than or equal to two. 99 00:07:02,210 --> 00:07:09,770 We print the value of one, then we print the value of two because J will be incremented to be equal 100 00:07:09,770 --> 00:07:13,590 to two and two is less than or equal to two. 101 00:07:13,610 --> 00:07:13,900 Right. 102 00:07:13,910 --> 00:07:15,380 Because I equals to two. 103 00:07:16,100 --> 00:07:23,060 We print the value of two and then when J goes to three, these condition returns, falls and we simply 104 00:07:23,060 --> 00:07:24,500 print the new line. 105 00:07:25,490 --> 00:07:26,190 Awesome. 106 00:07:26,210 --> 00:07:33,050 So now the lasting duration we know that equals the three and that's how we do it again. 107 00:07:33,050 --> 00:07:36,860 We simply execute the inner loop from one up to three. 108 00:07:37,100 --> 00:07:44,930 So basically all that has changed is just this condition of J as long as it's less than or equal to 109 00:07:44,960 --> 00:07:45,410 EI. 110 00:07:45,800 --> 00:07:51,620 So let's build in running just to make sure that, for example, if we have, I don't know, ten value 111 00:07:51,620 --> 00:07:52,280 of ten. 112 00:07:52,850 --> 00:08:00,560 So yeah, you can see the exact pattern that you would want to see on the screen printed exactly as 113 00:08:00,980 --> 00:08:02,240 requested. 114 00:08:02,660 --> 00:08:09,440 So this exercise was completed successfully and I think you're making really good progress with the 115 00:08:09,440 --> 00:08:10,550 material so far. 116 00:08:10,910 --> 00:08:17,600 That's not a basic understanding of the inner for loops and using like a for loop inside of another 117 00:08:17,600 --> 00:08:18,110 for loop. 118 00:08:18,500 --> 00:08:22,310 But I think we've covered everything up pretty good. 119 00:08:23,090 --> 00:08:30,260 And if you still have any questions, you may also use, OK, for example, just for your sake and for 120 00:08:30,260 --> 00:08:35,870 your simplicity, just use some table and to draw like what will be the value of. 121 00:08:36,590 --> 00:08:43,010 OK, let's say for I equals to one what will be executed J equals to one equals to two if it will be 122 00:08:43,010 --> 00:08:48,760 executed will whether the condition, the result of the condition will be true or false. 123 00:08:49,070 --> 00:08:56,240 OK, and simply running it or even on a piece of paper that will also be OK, just make sure that you 124 00:08:56,240 --> 00:09:02,690 understand this concept completely, even watch this video again if it's necessary for you. 125 00:09:03,740 --> 00:09:04,970 And yeah. 126 00:09:05,300 --> 00:09:13,250 So as always, guys, my name is Vlad and really excited and happy to teach you these C programming 127 00:09:13,250 --> 00:09:13,790 course. 128 00:09:14,450 --> 00:09:17,720 And until the next video, I wish you good luck. 129 00:09:17,720 --> 00:09:20,720 Practice a lot and we'll see you then. 12327

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