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
So what is going on, guys?
And welcome back to another amazing exercise in our programming course.
And this exercise, as I said previously, is not so easy.
But I think we will be good, pretty good with that.
So once again, we what we want to do in this exercise is to find if a given sequence is very ascending
or not very ascending.
And we talked about what is the meaning of these terminology, very ascending and not very ascending.
So just a quick reminder.
We said previously that we are going to receive a sequence amount of numbers that we do not know in
advance how many numbers we will have.
OK, so we will get, for example, five, seven, 10 or whatever numbers.
And based on these numbers, once we get them, we get them in some sort of order.
Right.
So we get the first number, then we get the second number and the fifth, the third, the fourth and
so on.
And I want to know a simple question is this sequence is very ascending or not basically taking any
value and asking the following question, will the next value be greater than the previous?
If the question is yes for all of the sequence, then we should simply print various sending.
Otherwise we should print not very ascending.
So now that the instructions are clarified, once again, let's dive into coding.
And what I wanted to start in this exercise is, first of all, understand the following concept, because
a lot of students having a hard time with this kind of exercise and kind of approach when you don't
know in advance how many values your program is going to read from the user.
So one approach is to use arrays, but in this case, we didn't study arrays yet.
So how can we know in advance how many variables we should create to hold these values?
So, for example, we have the following sequence like one five and six, let's say.
Then how can we know in advance that we need to create, let's say, three variables?
And do we actually need to create three variables?
And what will be the case if the sequence goes like this?
So three, five, eight and then one and then, I don't know, 10 and so on.
So will we need to create five variables?
Basically, how can we control this part?
And the answer is very simple.
OK, that's actually the main, let's say, trick in this exercise, and it says the following thing.
So you don't need to know all the sequence.
It doesn't interest you.
The main thing that you need to know and the main thing that you need to work with is basically just
to American values at a time so you don't need these values of three.
He does not need to know what will be the fourth value afterwards.
It simply needs to know that the condition between its neighbor, its first neighbor, its neighbor
and the right will be satisfied.
So as long as we know that, for example, we got the first value and then the next value, we we want
to know is if the neighbor is greater than me.
If so, then OK, maybe it's still very ascending.
And if not, OK.
So that's for sure.
Not very ascending, but that's how we are going to work.
We are going simply to check two values at a time.
Let's say the current value will be five and the previous value will be three, and then the current
value will be eight and the previous value will be five.
So the left value, the value on the left will be of the previous value and the current value will be
the value on the right.
And we are simply going to compare them in kind of pairs.
OK, and based on the result of the condition, we are going to make some conclusions.
All right.
So I hope you guys are with me so far because this exercise once again is not so trivial and it requires
your attention and your concentration to get it done correctly and right.
So let us start looking at this code.
So we have here is line eleven.
We have in sequence size and these value, this variable will simply represent the size of the sequence.
So in this case, the size is three.
In this case, the size is five.
So we just read this value from the user in advance and where we are doing that simply in these lines,
so printf insert size, which is the total size of the sequence, and read the value and store it inside
of the sequence size variable.
Also, what we have is these two variables, previous value and current value, which will simply represent,
as they just said every time, the value, let's say, on the left and the value on the right.
OK, so we will assume and we will nullify them and we will assume that these are given sequence consists
only of negative only of positive values.
And if we wanted to like to support also negative values, then a little bit of modifications should
be done.
But for the sake of simplicity of this exercise, we will assume that our sequence contains only positive
numbers.
All right.
So now that we know these match, let's also create some flag.
OK, then it will be a simple variable that will contain either one or zero.
OK, nothing special.
And this flag will simply let us know if we if we have a sequence of that is very ascending or not.
So basically, what do I mean by that?
I mean, let's assume awesome.
So now that we know this match, let's proceed with line 12 with line 20.
So we are asking you the following question.
If sequence size is less than or equal to zero, that's just a condition that I want to check and make
sure that the sequence has at least one value.
Otherwise, we should bring some don't message to the screen and which says, wait a minute, try again,
please.
OK, because that does not make sense of the sequence.
Size is less than or equal to zero.
There is no sequence right there.
In this case, we will simply print some error message and also some option is simply to exit the program
or like to run a loop that will read the sequences over and over again until we insert some good sequences.
That's also an option.
Some do while.
OK, so no problem with that.
Maybe Will will also cover it up here.
All right.
So that's OK.
So the LS is actually the main logic of the main core of this program, of this exercise.
So what we are going to do, we are going, of course, to use a while loop or better say it, do while
loop.
And what we are going to do is basically come here.
We can see that this is to do do this section, do this kind of block, these block of commands while
the condition is greater, this condition of sequences is greater than zero.
And what's the difference basically between a while and do while?
So a while simply says that even the first iteration of the while loop the condition should be checked.
But here we assume that we can do it also with this, because we checked the sequence sizes not less
than or equal to zero.
So in this case, we can start with doing this body once again.
But again, there is no actual reason why we could not have used even while here just instead of the
while.
I don't see it.
Maybe I'm mistaken because I'm a little bit tired right now, but that was my solution, so I'm OK.
So anyway, let's get back to business.
So that's the loop body.
OK, from line twenty six up to line thirty eight.
That's the little body in what we are going to do inside of this loop body is simply to read the values
from the user a one by one.
OK, so print f insert value and we are going to read the current value and store it.
OK, so we read for example if we have this sequence, let's copy that.
Let's come here.
OK, so that's the sequence that the first sequence and let's also copy the second sequence.
So these are just the two sequences that we have.
So what we are doing is, first of all, current value equals to one.
OK, so we are asking if current value is less than zero, then we can print some nice message.
No is not positive and that's it otherwise.
OK, because we don't want to to deal with this case.
Otherwise we will simply use these these body of the LS.
But let me just mark this place because I want us to come back to here later on.
So come back here.
OK.
And now let's talk about the Elsberry, so if the current value is less than or is less than or equal
to the previous value, which is not OK, which simply specifies we are not working with a very ascending
sequence, not very ascending.
So if that's the case, if we do not work with a very ascending, then we will simply turn off these
very ascending fact to be equal to zero.
So from this point on, the very ascending flag can never return to be one, because that does not make
any sense.
If we found out that the current value is less than or equal to the previous value.
And the result of this condition simply means that this sequence is not very ascending, then definitely
we will keep this flag as is equal to zero.
Awesome.
So then later on we will simply copy the previous value and simply copy the current value into the previous
value.
So we said that the previous value is always on the left of the current value is always on the right.
And for the first value that we read here, for the current value, we simply compare it here with the
previous value that equals to zero, which was just some assumption that all the values are going to
be positive.
So let's simply start with the value of zero.
And then of course, at the end of these L's condition, we are going to use sequence size minus minus
just to reduce the sequences by one, because we know that if we have a sequence of five elements and
we read just one element, then only a sequence of four elements is left, then three to one.
And that's it.
So awesome.
So that was the first iteration.
Then you come back again to the second iteration and you know that currently the previous value is one.
And the current value that you are going to read is five.
You are going to check these conditions and to do the following things.
So previous value will be now five and then six.
But in the other sequence example, it will be five and eight and yada, yada, yada.
So basically you've got the idea of how it works.
So here we will come to a point when we are going to have the previous value is eight and the current
value is one.
And this condition is going to be not to be satisfied, is going to be satisfied, actually.
So the current value is less than or equal to previous value.
So one is less than eight.
And that simply indicates that the sequence is not very ascending, that it's not growing up from left
to right.
So that's why we are going to set these flag to be equals to to be equal to zero.
And yeah, that's basically what we are going to do and once we are done, OK, once we are done with
this do while loop, we know what interests us the most is not what were the values of the current value
and previous value, because we lost most of them in the process.
Right.
We only left we are only left with the last two values.
So these value in this value in this case and this value the previous value of this and the current
value.
So we lose a lot of values and we don't actually care about them.
What we do here is about these various sending flag.
So if various sending five equals equals to one, which means our assumption in the beginning that the
sequence is very ascending or that it will be very ascending.
If it was correct, OK, then it equals to one then we can print.
This sequence is very ascending.
Otherwise, if this flag is not one, which means it was zero and if it was zero, then it means that
the sequence is not very ascending because this condition happened then in this case, we will print
the following message.
This sequence is not very ascending, which is kind of great.
Basically, we covered the main part of this exercise so far.
So let's just build and run it and see what happens.
Guys, what do you say?
So insert size the size of the sequence, let's say three.
And if we have three values like one, five and nine, then we are going to get a nice message.
This sequence is very ascending, but if we will try to build and run it, let's say with Valley five
valleys and we'll have one, three, five, four and let's say nine.
OK, so we can see that this sequence is definitely not very ascending because we have the previous
value of five and the current value of four, which is four.
Four is not greater than five.
Then in this case we should get a message of this sequence is not very ascending.
All right.
So I guess this is it.
This is clear to you guys.
If you still if you have any questions, feel free to ask them.
All right.
But I'm not finished yet.
I want simply to optimize this exercise a little bit because let's try to build it and run it once again.
Now, let's take a look at what happens here.
If we insert the value of, I don't know, of minus three, there was just some mistake and we inserted
the size.
So wait a minute.
Try again, please.
All right.
So that's not an option, optimal solution because the program has ended and closed.
And what I want to do is simply to try to to bring this message to the screen.
As long as the user has not inserted the the correct value, which is at least greater than zero.
So what do you think we should do?
Basically, my suggestion is to use do while loop, so let's do something like that.
So first of all, let's try to use just while loop, OK?
So while let's say sequence size is less than or equal to zero, while this condition is satisfied,
let's print the following message.
Let's pray and print F and also scan F and let's read it here.
OK, so as long as it's not equal to this, while it's simply print also this message.
Wait a minute, try again please.
And then insert size total sequence.
OK, so that simply looks OK just by using the while loop.
But the problem is that the sequence size is not initialized and we already check its value against
if it's equal or less than zero.
So that will be a problem.
And what we need to do is simply to optimize this loop to be satisfied that the first iteration will
be executed.
Doesn't matter if we have like like a sequence size is initialized or not.
So how it will look like basically basically let's just remove this line.
We don't actually need it.
So we will do do we will use do while loop.
So do this.
OK, as long as sequence size is less than or equal to zero.
OK, so total size of the sequence let's say greater than zero.
All right, so now let's build and run it.
So let's build and run.
It was the problem on the ls here.
The ELSS unnecessary of course.
So it's just.
That and simply a and it is it should be and let's build and run it, so insert the size of the sequence,
which should be greater than zero.
Let's say we said zero, it says is insert the size again, minus five instead of the size again, minus
three in sort of the size again.
OK, so you get a point.
It will ask us to insert the size of the sequence as long as we we haven't provided a normal size.
Right.
For example, five.
And then once we applied five then we can insert all the values.
Awesome.
So that's awesome guys.
I think we covered a lot in this video.
Just last question for for that.
Since we are already using do while loops and so on.
And you've got the idea of how it can be used here to insert the correct value.
So I want you to take a look at these lines.
OK, it's line twenty five up to line twenty nine.
And we said, let's come back here later.
Right.
So we are coming back and what I want you to, to see here and take a look what is the problem here.
So let's say that we will do the following thing, so let's build and run it.
So this it will be of size, let's say three and the values are going to be like that one minus one
and two.
OK, and let's say three, for example.
I don't know what you're getting.
It's getting kind of problematic.
So the sequence is very ascending, although we inserted a value of minus one, we just got some printed
number is not positive, particularly a lot of things have gone wrong here.
So my suggestion is to use the similar a similar approach to what we've done here with the with the
do, while as long as the current value we are inserting, the user is inserting is is not greater or
equals zero.
So let's do the following inside of these.
Do, let's do OK, let's do this following code.
OK, so do this, all of that.
Let's do while.
Let's do it wild current value is less than zero.
So in this case, these else is also unnecessary.
OK, I've done I've done some modifications with you guys because initially I wanted to talk about it
with you.
So what will be the case here?
The case here?
We will ask the user to insert the value as long as a value is not on.
Is not greater or equal to zero, so now it will look a little bit, ah, a little bit different.
Let's see how it looks like.
I don't know what really what's what's option what option is better.
But let's say that we as here three or so, one minus one and then two, three.
OK, so, um, and also.
Yeah.
I'm not sure that this option works better, you know, because we don't see that we had some problem.
And so these option also can be optimized and um.
Yeah, no actually guys that was kind of kind of a question, but I think that the better option would
be simply to get it back as it was previously, because you see, there is no actual reason to do the
while here.
At least I don't see it right now.
But once again, it's a good thing to try to see if it works OK, because that's my suggestion is how
to approach exercises of different kinds and of different complexities.
Give it a try because you don't know if it will work for one hundred percent and like to take a look
and think about what what would happen if we have used here a while loop do while look, maybe it will
improve a little bit.
My code, like in this example, I think it made a great improvement.
Of course we could have done here also something different, but it's also OK.
So yeah, guys, this is it for this video.
This was not an easy video, right.
Because we covered a lot and this exercise is not this simple one.
So once again, we found a sequence is very ascending or not based on getting these inputs from the
user of an unknown size of a varying size sequence size that we got from the user.
We used the very ascending flag to find if a sequence was basically ascending or not.
And yeah, this is it.
Let me check if I have anything else to add here.
And yeah, there is actually one thing that I wanted to add here is regarding this condition where we
are going to work with the flag, where we are going to modify the flag itself.
So let's simply copy this flag here.
And I want to ask you a simple question.
Once we found out the sequence is not very ascending, then what is the reason to keep on running additional
iterations inside of this loop?
So let's say you had a sequence of thousands of thousands of elements and all of the elements, let's
say like I don't know, all of them are various sending up to, I don't know, a million.
OK, so it's a million or ten million.
It's a million or so.
But the problem was here that the second element simply breaks the rule and says that this sequence
will not never be will never be very ascending, even if all of these elements are very ascending.
But here we have a problem.
This sequence cannot be very ascending.
So we know that by using this condition and various ascending flag, we'll be equal to zero even if
we run.
These are four or five iterations for a 10 or for the whole sequence.
So there is no reason to execute these whole loop over and over again once this condition has been satisfied.
So what do I mean by that?
I mean, let's simply break out of this for for a loop once we found that this condition is true.
OK, so we said the various landing flag to be equal to zero.
And then we break out of this loop and we simply go here and ask the following question.
We know that this condition will be false.
Then the else is going to be executed.
This else is executing when the variable very ascending flag will be equal to, for example, zero.
Right?
Basically not equal to one.
So, yeah, that's a sign that is the optimized solution for this exercise.
So, guys, I hope you like this video.
Please leave me some feedback, some review.
Let me know what you think of the course of the material so far.
And yeah, I think I will see you in the next video, probably.
Right.
So my name is Vlad, this is Alphatech, and guys have a great day, only positive vibes.
And until next time, I'll see you then.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.