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 righty.
Right here, right?
All right, so let's start solving these exercise.
OK, guys, are you ready?
Let me make sure.
Yeah, I think you're ready.
The recording is ready.
Everything is set up.
Let's start.
So what we know here is basically that we are going to write down a function, OK?
And these function is going to have basically just one number and one digit.
And we are going to find out, first of all, how many digits simply are less then than this digit in
these given number.
OK, and print the result of the final return thing of the average of the of those digits.
We are going to leave, let's say, for the second step of this solution.
So regarding the first step are let's first of all, define the function signature.
So what do you think should be the function signature?
Shouldn't be void and I don't know, floating point character.
What do you think, guys?
So here you can see that the final result printed is just an integer type, right.
So does it make sense that the function will be of an integer type or maybe instead of the function
should be of a void type since the type of the function is printing?
The answer is absolutely no, because the function is going to return something and this return value
is going to be an average of those digits.
And if it's going to be an average, then chances are high that it's not going to be an integer, but
rather it's probably going to be of a floating point type.
OK, so.
Let's say float will be the type of the function, let's say, I don't know, let's say lower than digit.
OK, lower than digit, the name of the function and the function is going to receive two values in
number and eight digit digit.
OK, so that's the signature of the function.
You know, what should be the next step?
Basically.
What we have to create, let's create some I don't know, let's create counter equals to zero.
OK, and this counter is going to represent the total amount of digits in numbers which are smaller
than the digit itself.
OK, so let's say the following thing are.
So let's start with what do you think should be the best way to go?
What do you think should be the best way to go?
Let's start with the with with with let's start with some basic cases.
Yeah.
I think base cases may be OK.
Let us assume that in this exercise, actually, we can treat two different options, the first option
is the fact that a given number may be also like negative or positive.
OK, we did not specify the name itself should be natural.
So now maybe also positive or negative.
And that's something that we can simply solve by because we do not really care if the sign is positive
or negative.
We just care about the digits.
Right.
We don't care if here will be a minus sign.
So in this case, what we can do is just do the following.
So if nothing is greater than the then zero, that's OK.
But if the is less than zero, then in this case, what we would specify is basically none will be equal
to number multiplied by minus one.
OK, simply reversing or kind of disabling the minus sign so that this way it will be easier for us
to work.
OK, additional thing that we may be considered to be using is the fact that we know that digits are
basically something in the following range.
Right.
They vary from zero.
One, two, three, four, five, six, seven, eight, nine.
And that's it.
OK, that's the range that the digits vary.
So the lowest digit here is zero.
OK, so that's also fine.
And what we have to do now to start doing is doing the following thing, the following thing.
As long as NUM does not equal to zero.
OK, as long as NUM does not equal to zero, we are going to ask the following question.
We are going to ask if num modulo 10, which basically says take every time the rightmost digit in a
number OK in a given them and ask if it's less than digit if that's the case.
OK, if that's the case, what we are going to do is to say counter.
Plus plus.
OK, Gunta plus plus.
And right afterwards we are going to say that number will be divided by 10.
OK.
Is everything clear so far.
Nothing special, nothing complicated.
Simply taking into account that in every iteration.
OK, we will take this nominee to read over and over again, again, again.
Until we reach that fact that NOM does not have any digits at all, meaning it's zero.
So if NUM module 210 is less than digits, calendar plus plus num equals to num divided by ten.
Meaning we start with this number which I give to is less than three, maybe the counter goal plus plus
then we divide these num by ten.
We are just left with one three five seven.
Then we do the situation again and again and basically that's it.
OK.
And finally what do we have to do is simply print out.
OK, print out our total amount of digits in num, ok.
Or basically in percentage the.
Total amount of digits in percentage is less than percentage, the total amount of digits in R equals
two equals two percentage, OK.
So now we are going to specify these for a percentage now and here we are going to specify specified
as counter.
So simply saying the printing operation is pretty much complete.
What do you think?
I think that it is a complete.
And one last thing that maybe we have to take into account is we have to take it into account is the
second thing that these function should return the average of those digits that are less than digit.
So if we want to find out what should be the average of these digits.
So one thing that you have to consider using is basically to sum up everything so far.
OK, so how do you do it?
Basically, you do it in the following way.
So you say like this.
So let's say I go into some OK, total sum, total sum equals to zero.
And here on every duration, OK, on every iteration.
We are also going to like to take the digit, the rightmost digit and added to this sum.
OK, so now what do you tell the rightmost digit.
You know, once we are done with this step, we can simply return.
What can we return?
Total sum, total sum divided by counter.
OK, and what do you think?
Is this OK or not?
We basically should also add the casting.
OK, guys, so that's pretty much it for this video.
I think that everything is correct here, if I'm not mistaken, on any any line, let me know if you
execute the main function for it and everything works as expected.
Of course, there are also additional options to you to, like, kind of solve it and to treat some
base case like, I don't know, int num num equals to zero as well as the digit equals to zero.
What should be what should happen in this case or basically if the digit equals to one in num equals
to zero.
OK, so how should you treat this case.
And basically that's something I'm leaning up to you.
I think you can also added on your own and.
Yeah.
So you simply regarding the printing, we understood everything correctly regarding the average.
We simply found out the total sum of all the digits that satisfy this condition, that the rightmost
digit in NUM is less than the digit itself.
And we summed up all of these digits.
And finally, we are if we want to find the average, we took the total sum and we divided it by the
total counter of all the elements.
So there you go, guys.
Thank you so much for watching.
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.