All language subtitles for 10. Printing1ToN and NTo1 - 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
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

Original subtitles

OK, so now that you tried to solve it on your own and the instructions are clear, we are going to

see how this can be solved together.

Let us start with a simple exercise with a simple, ah structure that first of all, we are going to

understand what is basically the type of such a function.

What do you think these function should the return should be of a type in to double flow?

What do you think, guys?

That's very important to understand this part, because usually a lot of people find it difficult to

to make this type of the function.

So what do you think?

Basically, we know that we even don't have the word return in this question, so probably this function

is not going to return anything.

The fact that these function prints some information to the screen does not necessarily mean that these

function should return something right.

So we will assume the type of the function is going to be of a void type.

OK, so void and then rule specified preened one.

I don't know, two n ok, that's the name of the function.

And this function is going to receive.

What do you think it's going to receive some number n so end and OK.

And once this structure is clear, the signature is clear, we are going to run the loop body so the

body will be something like this.

First of all, understand what you are going to do.

I mean, what do you think should be done?

Do you think that if we simply print print f I don't know what percentage D in here, if I m is this

the correct approach.

What do you think guys?

Do you think that if we run the function now, let's just use it here.

So let's just run this print F to N and let's see what happens.

Basically I'm going to solve it together with you and to see all the different different options that

you also may have tried.

And basically some of them worked this way, some worked the other way.

So let's see.

So print one to n that specify for OK as our example.

So if we build and run it now, then in this case what you will see is just the value of four printed

to the screen.

That's not something that you want.

You want all the numbers from one up to four.

So what do you think is missing here?

Basically one of the things that are missing here is the recursive function call.

So let's do it.

And what we need to end now is print.

That's a print one to end.

And if we will specify n here, what do you think will happen?

What do you think will be printed the the screen.

So let's quickly don't write home.

I will build and run it and stop this execution right away.

But you can see that four is printed and less time to the screen.

And why is that.

The reason is very simple because we don't have any stopping condition and the this recursive function

call itself over and over and over and then it prints these n so that's also not something that we want

to happen.

So let's add some stubborn condition.

What should be in this case, the stopping condition in such a case?

The stubborn condition should be basically what do you think?

It should maybe be one.

Right, because we print all the numbers from one up to and from one up to M, so let's make it like

if and.

If is greater or equal to one, then only in this case let us execute these following lines of code.

So let's just copy that.

Copy it here.

Oh, good.

Awesome.

So that's what we will have here.

So do you think anything has changed so far?

Absolutely not, because we still call this function over and over and over again and and will not be

documented.

So what do you think if we had here and minus one right now, what do you think will happen?

What do you think will happen?

Don't try to execute it.

Look at the code and trying to think for yourself what would happen here.

Do you think that this result will be printed to the screen like one, two, three, four, or maybe

some other result will be printed to the screen.

So let's build and run it and see what happens.

So there you go.

You can see four, three, two, one.

Pretty much what we wanted just in some reversed option, right?

We don't want for three to one.

We want one, two, three, four.

So print one to and you can see here and end.

First of all, we print four, then we call this function for four with a value of three.

Then we go print three and then we call it for a two for one.

And then this result is false.

And then basically we stop our recursive calls.

All right.

So that's clear, OK, that we print for three, two, one, want the screen and that's amazing, but

what should you modify?

What should you modify basically?

Remember also this solution, because the solution is can be copied and it can be shown like print and

into one print and one that's the other other solution.

OK, so this function will print all the values from M to A given from A given M to one, and these

function should print all the values from one to M.

So what do you think should be changed here?

And basically what should be changed is probably the order of these two lines.

So flying 15 and 16.

So you should change the order.

Let's try to basically move this line to be printed out after the recursive call.

So this way, what you will do.

OK, let me write with you, OK, so that it will be even clearer to you.

So we are calling with four.

OK, so that's the first instance.

And let's say that's the console application where all the results are going to be printed.

So we call this function with the value of four.

OK, and previously we just printed four and then three to one and so on.

Now we call our call this function with four.

We check this condition.

It's through.

We are going to now call the other function.

Another instance with the value of three.

And then we are going to call these function again with the value of two and then again with the value

of one.

And then what we are going to do is to call this function with the value of zero.

Right, because and minus one is zero.

So we call this function with a zero.

So if any is greater than or equal to one, that's not true.

So this function has been executed and it has not done anything.

So then we go through this function.

OK, this instance, this instance call executed this function of print one to end for zero.

Right.

That was the call for this function.

And this function has been executed.

This line has been executed inside of this instance.

And then we will execute print F percentage.

So we are going to print one to the screen and then these function is over also.

And then we come back to these function, these things dence, these things, those called these print

one, two and four one for this value.

This line has been executed and now we are going to print the given value, the given N, which is two,

and then we are going to do the same for a three and four.

And basically that's what we are expected to see on the screen.

So I hope this is clear to you guys.

Very important, this order.

OK, so if you take a close look at this option right here, you will see that the order is different

between the recursive call and the print command and that this will result in printing all the values

from N to these given one.

OK, is this clear?

Do you.

Awesome.

So let's just once everything is clear to you, right.

Let's just clear this screen and let's basically call this function once again.

So we use our main OK, so print one to him.

Let's see.

Is something even nicer here.

So quick answer and no.

And then the user is going to specify the number.

So it's can f let's use here also some ain't no scam F percent the and story inside the variable.

Now let's say that print have all the values from one to an hour and let's say here all the values will

be printed because we are going to call this function, print one to end and pass the value of NUM.

OK, let's remove this line now with basically build and run it.

So let me just close this before.

OK, so build and run and let's see what's going on.

So enter a number.

So let's say for so all the values from one to an hour.

One, two, three, four on this of course could be replaced with some percentage.

No problem with that.

Let's check it out also for ten.

So let's get it.

Ten all the values from one to M in this case it's ten are one, two, three, four, five.

Six, seven, eight, nine, 10.

So, yeah, this also could be modified like this and here specify now, not a big deal.

So I hope this is clear to you guys.

Also, one thing that we also can modify a little bit is just let's take it like this.

Let's take it like this.

All the values from percentage D to one also created the other way.

And basically we will use here this kind of nice line printer to print and to one.

OK, so let's build it and run it and see what happens next.

So fine.

Or let's just add additional new line here before so that it will be clear.

Print F, so enter a number five and all the values from one to five are one, two, three, four,

five.

And all the values from five to one are five, four, three, two, one.

Hurray!

Congratulations guys for completing these exercise off recursions recursions section.

Not an easy one, but I think that is a very good exercise.

It covers up a lot.

And in the next video we are going to proceed with some variation of this exercise.

And hopefully you will try to solve the next exercise totally on your own because it's going to rely

on the understanding you had to gain in this one.

So with that being said, let me know what you think of this video.

What do you think of this?

Course, it's very important for me to get some feedback from you, to get some review, to get some

comments so that I will know that my hard work is really pays, really pays off.

So thank you, guys.

My name is Vlad Alphatech.

I'll see you next time.

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