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
What is going on?
And in this video, we are going to solve this amazing and kind of long exercise about rational numbers.
OK, so that's what we are going to do.
We are going to write down.
Here are the instructions write down his product called rational, and these drugs should basically
represent a numerator and a denominator.
And these strength should also kind of simulate the operations or basically not the struct itself.
But for this point in time, we will use separate functions that should get and work on various.
Struct regional struct variables, so that's what we are going to do.
And now let us start.
All right.
So I hope, first of all, that you tried to solve this exercise on your own.
It's very important and very crucial to your understanding.
Can you hear me?
Right.
So now after you've tried it on your own, we are going to do that together.
So first of all, we need to create the structure itself.
And the way we do that is simply by writing down the following line typedef struct regional, specifying
the fields of this structure and the fields are going to be is following.
There is the numerator and there is there the numerator denominator.
So it's going to look like this.
Am I going if I'm going to get my awesome pen?
So basically, every rational number is going to look like this.
So this is a rational, rational number.
You're also getting -- much better after my tutorials, so this one here is basically the nominator.
Noumea.
Rita, and this one is.
The denominator.
Then nominator.
OK, so two fields representing irrational number.
Awesome.
So a variable of the irrational number is basically going to have these two fields and they are kind
of representing this structure.
OK, good.
So let's start working with the functions.
And the first function that they asked us to make is the increment function.
So if we want to write down a function that should work on a rational variable and incremented by one
before, first of all, need to understand the process of working with increment.
And the way to do that is simply writing down in increase meant.
So before I write down, the implementation is I already told you write down on a piece of paper the
main steps that you want to follow in order to complete this process.
OK.
You following.
Awesome.
So we want the following operation.
We want to take some rational number and simply adding one to it.
That's the default increment that I'm going to use.
So basically, just before we move on to this increment, this note, I got to say to you explicitly.
So in this case, when we are going to work on these basic, let's call it structure of numerator and
denominator.
Well, for simplicity, we will assume that both the numerator and denominator are greater than zero.
Okay, I'm not going to dive into all the details of what happens if both of them are less than zero,
or if any of them equals to zero, or if any of them is a negative.
So for now, let's assume for simplicity, OK, that both of them are zero.
OK, so write down this note.
Awesome.
So what we need to do now is to understand what is the result?
First of all, on paper of this operation, it's not going to be like if you take one divided by three,
OK, one third and you add one to it.
The result is not two divided by three.
That's not it.
What you do is you do some common ground common denominator.
OK.
So basically, you expand these value to be represented as, for example, the denominator of this is
D, this is an OK and for a numerator and D for the denominator.
So this will look like this and divided by de plus d divided by D right d, divided by d denominator
or divided by denominator is the same number.
We just represent the value of one as a whole, as simply denominator by denominator of this one.
And this will allow us basically now when both of our rational numbers have the same denominator, we
can write the result as numerator plus the denominator.
This will be the result.
So for example, if we come again to this question, OK, we can say that the final result will be what
the denominator, which is three it will be one the numerator plus three.
So the final result should be four divided by three.
OK.
That's the basic way to work with incremental one by one.
So now that you realize what you have to do on paper?
Oh, sorry, I think I have covered this solution, so let me get it like that.
OK, so this is it.
This is this is the solution right here of the incremental incrimination.
So let me write it down a little bit above.
OK.
So, yes, sorry about that.
I was basically covering everything, so increment is basically the result should be like numerator
or divided by denominator of plus one equals.
Two want to end plus rd divided by d k.
Hopefully this is cleared for you.
If not, feel free to ask any questions.
And we gave a couple of examples.
Also, if we give another example, it's say two divided by five plus one will be equal to five.
And we take two two divided by five plus five, divided by five is one.
So that will be the result.
Seven.
Divided by five.
Basic math.
OK, so now let's take a look at the function implementation.
So we are going to uncomment this part.
OK, well, let's also remove this one.
We already know it.
OK, good.
So.
We are going.
To make a function of avoids type because we do not expect this function to return anything, so we
are going to call it regional increment.
It's going to get an address of some existing of some existing
regional variable.
And then we are going to say that the result, no matter enumerator, OK, that the result numerator
will be equal to the numerator itself that we take.
This is this is it?
And also, we are going to add to it its denominator.
OK, so numerator plus denominator, that's what we are going to do.
That's basically what we do.
So let's take another example.
Let's take a look at this example we have here.
First of all, this is our rational object, rational variable.
It has the numerator of two and the denominator of five.
And then we say that the result is going to be the previous numerator plus plus the denominator divided
by denominator.
That's what it's going to be.
So we can say that this function is over.
It's done.
So one question for you is how you can call this function and you can focus this function in very simple
way.
You can simply write down.
Then when you are going to check out in the main function, you can write down, create some rational
number.
So create regional are one with, I don't know, one in three values.
OK.
And then what we are going to do is simply make this function, call this rational increment.
And then specify here the address of our one.
That's what we are going to do.
So now if we take a closer look than what we will see that after this line, what basically has happened
is that we increased this value to be four divided by three.
That's everything about rational increment.
Awesome.
Now if we take a look at the next one, which is decrement.
It's going to be pretty much the same.
OK.
We are simply going to expand it a little bit.
And we are going to say that the numerator equals to the previous numerator minus the denominator.
So he's going to look like this.
It's going to look like this, it's going to look like one divided by or at, let's see, three divided
by five.
Let's give another example of seven divided by four minus one.
It will be equal to seven.
All of the divided by four minus four, and the final result will be three divided by four.
OK.
That's it.
So that's about the decrement operation, very similar to the increment.
It will be called the calling to this function will also be very similar.
OK, so I hope it's clear.
And both of both of them of these functions were basically of a void type, since we do not return anything,
we work on the same variable, so we send the address of these variable.
Later on, we have these addition function and these additions function basically receives two rational
variables, calculates the addition of both of them and returns the result.
So what you need to understand is whenever you are going to work with two rational numbers, let's say
we will call the first one and one divided by one, which is numerator one divided by denominator one.
This is the representation of just one rational number, and we want to add to it another rational number
and to divide it by two.
So the way you do it is not just like this and one plus and two and D two d one plus the two.
That's not how you do it.
OK.
That's not I.
Basically, it's not something that I have invented.
That's math.
OK.
So there are strict rules that we should follow and how it's going to look like.
First of all, we do some common ground, some common denominator and the common denominator of the
result.
OK.
This is this is the first rational number are one.
This is going to be our two and this is going to be.
The final result.
OK, so the final result denominator is going to be one multiplied by two, and the numerator of the
result is going to be in one multiplied by 0.2 plus and two multiplied by one.
That's math.
Ladies and gentlemen.
OK, so we create a variable called result of rational type.
This variable has field's denominator and nominate numerator.
So we will calculate the result field result dot denominator will be equal to our one dot denominator
multiplied by our two dot denominator.
This is it.
This is this part.
And also we calculate the numerator.
How do we do it?
We say resolved dot numerator, which is this part, will be equal to our one numerator, which is and
one multiplied by our 2.9.
I mean, the denominator, which is the two plus are two.
Numerator multiplied by our one denominator.
And then we calculated the result numerator.
That's math.
Once again, math, math, math.
There are rules for working with rational numbers.
We just need to understand them.
And then to use these rules and construct and create and develop different functions in our programming
language.
OK, so that said about rational edition.
And we return.
The return type is rational because we return some value, which is of type rational, some variable.
I'm not talking about in this example, whether it be it will be more if it will be better to use here,
a pointer or references and so on.
Doesn't matter.
OK, for now, let's use it as simple as this just to demonstrate the usage of these functions.
OK, good.
So the function call itself, for this part, is going to look like this.
Let me just show you the function call is going to look like this.
OK, suppose that you have created rational are one.
Which will be equal to one three and are a two, which will be equal to two and five.
So then the result you will create rational are three will be equal to what two rational additions of
who are one and are to.
That's it.
And then in our three, there will be the result of the addition between these two between these two
rational numbers.
OK.
Who I hope I hope you're following me so far because we are just getting like another one after the
other, but it's very important for you to understand each and every step here so you can feel free
to stop these video.
Watch it once again and then replayed and so on.
OK.
Awesome.
So this party's over, but we are not done yet.
There are additional seven functions that we need to follow.
So let's go over them quickly.
The next one is basically this obstruction subtraction.
So what we do here is basically we do a subtraction operation.
We take our one minus our two, also a mathematical operation.
Very, very similar to addiction operation.
We simply take two regional numbers and one d one minus and two D2.
And the result is very simple it's d one multiplied by D two and and one multiplied by D two minus and
two and two multiplied by D one.
That's exactly what we've written here.
This is and one this is.
What is it, D2, right?
And one multiplied by D, two places and two.
This is the one so and one multiplied by two minus and two multiplied by the one that should be the
numerator of the result.
And regarding the denominator, it should be the one multiplied by the deal, and that's exactly what
we can see in this line.
Three, eight six.
D1 multiplied by D2 returning the result.
OK, so this is not about subtraction operation in the function call, it's very similar to this one.
Just like this instead of fractional ED. You simply write down rational subtraction.
OK, then you use multiplication.
Multiplication, so in multiplication, that's very, very simple.
You simply take if you need to multiply.
Let's see one rational number by the other.
Then the result is very simple, it should be and one multiplied by into.
In two and divided by one, multiplied by two.
That's it.
And that's exactly what we do here.
We get to rational numbers, are one in Iowa to multiply, the denominator is putting it into result
that denominator.
And also we multiply the numerator us and then put the result into the numerator of field.
That's what we do.
Awesome.
So let's proceed.
Now we have the lesion.
Night vision operations, very, very, very similar to multiplication, just that it works a little
bit different.
So we have in one divided by one and we try to divide it by and two divided by two.
So the result of this is basically in one divided by one, multiplied by what?
By D2 divided by into.
OK.
We simply flip this regional number when we use day vision and then we use simply multiplication.
So the answer, whether this is going to be and one multiplied by two, divided by one, multiplied
by end to.
So the denominator is going to be the one denominator, one multiplied by numerator to.
And the numerator of the result is going to be numerator one numerator, one multiplied by denominator
to.
OK, very, very simple.
We could also to take advantage of using racial division by simply leaping one of them.
OK, the second one and then calling the regional multiplication between the flipped one and on one.
But let's keep it simple.
That's also an option.
I'm not saying no, but for now, that's the way we solve it.
Let's move on.
We ha we have a little bit left.
So, yeah, I think most of them are the same, pretty much the same.
So it will be easier to explain.
So in this function, what we want to do is to kind of simulate the comparison of if our one is smaller
than our two.
So we call this function smaller, rational.
And what we want to do is to ask a simple question if.
One regional number.
OK.
Ah, one is less than.
Another rational number are two.
That's what we want to do.
So how you would do it?
You do not simply ask if in one is smaller than in two and Diwan is smaller than the two.
That's not how you compare who is greater and who is smaller using rational numbers.
Once again, these are math rules.
That's not something I've invented.
OK, so.
So, OK, so what do we have to do in order to give an answer to this question is to make for both of
them some common ground?
OK.
There are also additional ways that we can do it, additional techniques.
But I'm going to show you some basic technique.
So we make a common ground for oops, why did it become bigger?
So we take these no, and we represented by doing the following.
OK, let me just make it smaller so everything will fit.
So and one the one hand and two D2 assuming that we know that all of them are positive.
OK, so what we ask is the following question we want to represent it as this, we want to say, and
one divided by one, and we will multiplied by d two, divided by two.
We can do it right because the value of it is one, and multiplying the any value by one will not change
the value itself.
Right.
And we do on the same side here, pretty much the same just when multiplied by d one, divided by D
one.
OK, also, that's just one we can do it so and one multiplied by two, divided by one, multiplied
by two.
And then we take a look here and we see and divided by d one.
Multiplied by the want and multiplied by two, that means that here we have common.
Dear.
No, me neither.
We have a common denominator.
And once we have a common denominator, we can decide which of these rational number is greater or smaller
just by comparing the denominator, the numerator, okay, just by comparing these parts.
We can decide who is greater.
So that's exactly what we've done here in these lines.
We calculated the R one denominator to the enemy.
OK, we simply expanded it.
And representing.
Now this is our one, and it has the same values here, just in a different representation.
And this is R2 the same as here, just differently represented with the same denominator for both of
them.
So what we do now is simply ask if this updated numerator, which is in one multiplied by two?
This is it.
It has been updated right here.
OK.
If it's smaller than this one, return one.
If it's not returned, zero one means that our one is smaller than our two zero means that it's not
smaller than our two.
That's it.
OK.
And the way you call these function is simply, you write down smaller, rational are one or two basically
on some two rational numbers that you use?
And that's it.
And in a very similar way, you do the same or finding out larger regional.
OK, let me simply remove it from here.
Very, very simple.
Very, very similar.
I simply copied it from the previous one and just changed the sign.
That's what we want to check out now is simply instead of this sign, we are looking for this sign.
That's it.
Of course, there are out there techniques that you can solve it.
This one, I think, is not the most complicated, hopefully.
So let me know if you have any suggestions.
But either way, this is good and this is good.
And now we can proceed to the last one.
Which are also very, very similar.
These are the equality and not equality signs.
So once again here, whenever you want to check if two regional numbers are equal to one another, that's
not enough to ask if just the numerator equals to the other numerator and denominator equals to another
denominator.
OK, although that's one option, but we can also say that.
These two are rational numbers, four divided by two.
And let's say eight divided by four.
They are also kind of the same.
OK, right?
Because this is two and this is also two if we take a look at it.
So this way, we kind of also solve this problem.
And finally, these are not equal.
Rational can also be can also be very similar to these one.
We simply make some common ground, some common denominator and compare between the new updated and
extended numerator is that's what we do.
So we are done with this functions.
And now what you need to understand is that, first of all, to make sure that everything is clear in
terms of math, then that everything is clear in terms of the functions, names and the purposes, and
there are types and what they receive and what they return and so on.
And lastly, understand that these exercise can also be extended and we can add like operations like
ARM Irrational Number and then we can also add like a function called reduce to simply if we have these
value OK, instead of keeping it this way, we can reduce it to be like one divided by three.
But that's not for this video.
That's something you can do also on your own.
Or maybe we will do another video.
Not sure about it?
Probably not.
But yeah, this is it for it, right down the main function.
Make some plays with various rational numbers.
Make sure that you can call these functions that they work appropriately.
And let me know if you have any questions.
I hope you like this.
VIDEO This was a very comprehensive solution that took us some time.
I don't know how much time.
But it took us some time, I think it was about half an hour, but we cover it up a lot of things.
So once again, guys, I hope this effort will pay off and that you will find this information useful.
Please let me know if you like this VIDEO If you have any suggestions, if you have any questions,
leave some feedback, some review that helps me.
A lot keeps me kind of.
Wanting to work more and to give you more value and more content, more updates and so on.
So thank you, guys.
My name is Vlad.
Keep on practicing.
Keep on moving forward and you are bound to succeed.
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.