All language subtitles for 4. Print the sum of all numbers from 1 to num - 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

All right, so let's start diving into coding and in this exercise, what we have to do is to write

a program that gets some numb, OK?

And this program, what it should do is simply to calculate, calculate the sum of all the values from

one to three and so on, up to num and print the final sum.

OK, so preened creates the sum.

So this exercise is not very difficult.

Again, it's very similar to the exercises that we've already solved.

So in print and turnham and read the num value, that's the first step that what we should do and not

writing it once again.

So we are just using this code snippet.

OK, and now we are going to do is simply to use some for a loop for example.

OK, so let's use it for a loop and create additional variable called AI and this variable will be used

for our loop.

So for I equals to zero as long as I use less than or equal to num.

OK, basically let's start it from one end on every duration we are going to increment I by one and

that's how you do it.

Then let's use the following approach so we should, we know that we should sum all the values.

So for that let's create a new variable and call it some let's initialism to be equal to zero.

So on every duration we are going to take the previous value of sum and add to this value the value

of PI.

So some the new sound value equals to the previous some value plus the value of AI.

All right.

And that's how you calculate it.

So some equals the sum plus I.

So if we have like I don't know, Nomikos to five.

So you get here with equals to one and we know that some first of all equals to zero, then some will

be equal to one because it's zero plus one.

Then I will be equal to two because I will be incremented.

So it will be one plus two, it will be three and then one three plus three, it will be six and so

on up until you reach in this case to what it is.

Fifty fifty.

Yeah.

So it will be 15.

So that's basically a simple solution on how you can iterate over all the numbers, all the natural

numbers from one to NUM and calculate them and add them to this sum.

And finally, what you have to do is simply to print out a solution so that the sum of all the numbers

and numbers from one to two percentage need is the Geany.

Right.

So now instead of these percentages, we will use NOM, right.

Because the sum of all the numbers from one up to ngom is in here.

We will use instead of this placeholder, we will use some.

So very simple.

OK, so let's build and run it and see that it works correctly.

So let's go enter Nomsa five.

The sum of all the numbers from one up to five is fifteen, which is correct.

And we also see I've seen an example of using seven, so let's go like seven.

So the sum of all the numbers from one up to seven is twenty eight and that's freaking awesome.

That's amazing guys.

It works exactly as we expected it to.

So if you still have any questions, feel free to ask them right now.

And one thing that I want to show you is how it can be done.

Also using the while loop, because some of you may have solved this exercise using while loop.

So let's go with a while loop and basically with the while loop it maybe even easier because I don't

need this I.

OK, and I can just go like this.

So let's try this approach.

So while num is greater or equal two to one, ok then in this case let's use some equals to some plus

num case or will it simply take five.

OK, and we need just to decrement it now minus Munnings.

So if num equals to five the condition is true.

So we take some equals, do some plus five and then num will become for some plus four and so on.

So we simply start from the end to make this sum from the end to one.

So num num minus one plus, so on, so forth.

Plus three, plus two plus one.

As long as num is greater or equal to one, the only shurat are coming in.

This solution is that you kind of lose the value of NUM if you need it for further.

Analysis, so just like in this case where we print this message, the sum is probably going to be calculated

as it should.

OK, but what do we have here?

As long as nothing is greater or equal to one, then let's check.

What is the problem?

What is the problem?

OK, so we're expecting before.

Oh, sorry about that.

OK, so that's how it is a problem.

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

So there are number five, so the sum of all the numbers from one up to zero is 15.

So the sum was calculated correctly.

But these numbers, OK, which was replaced in these placeholder is zero.

Why is it zero and zero?

Because I told you guys that that's the problem.

If we are using this approach, like if we want to rely on these numbers, let's run.

These numbers will be decrements.

So one way to solve it is simply to use the additional temp variable that will help us.

So in temp and here we will use like temp equals to.

No, just making a copy of NARM in here instead of now we will use temp once again so that if we need

to print the value of Naameh afterwords, we will not lose it because we used here some temp variable.

So in this case I think that both of the options for for a loop and while both of them require you to

use additional variable, if you want to rely on these numbers after the loop is over.

So let's build and run it finally to make sure that everything works as expected.

So let's go with seven.

So the sum of all the numbers from one up to seven is twenty eight, which is correct.

So yeah.

So now you've seen how it can be done using while loops and using for loops.

And that's just I'm just curious about what will be the sum from one up to ten which it will be fifty

five.

Awesome.

So you know how it can be done using the wire loop and using the for a loop which is freaking awesome.

So with that being said, thank you for watching.

Thank you for practicing.

And you are expected to receive more difficult exercises in the next videos.

So until then, have a great time.

Take a break.

Drink something nice.

Eat something, some snack, maybe.

Maybe not.

I don't know, whatever you like.

So my name is a lot.

Guys, this is Alphatech.

Thank you so much.

And I will see you in the next videos.

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