Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
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.