If you can't understand why we use % to get a number less than the one we want it's because if you divide by 3 for example you have to get a number less than 3 because if a number equal to 3 or more existed than 3 would divide it, so it wouldn't be possible for example 12 / 3 = 4 because we can no longer divide by 3 and there is no remainder so it's 4 if there was a remainder that would be the % and the remainder can't be 3 because then the result will be more than 4 . It took me some time to get that, thank you God.
The modulus operator gives you the remainder of a division. The result will always be 1 less than the denominator. So you have to see how many times does the denominator "fit" inside the numerator. Whatever is left over is your result. You just have to carry out the division.
An operation gives a result on the same data type as its operands. Both 37 and 6 are integers, so your result has to be an integer. 37/6 = 6.16666..., but because it has to be an integer, you lose the fraction part, 6.
@@VelcodeCS yeah but,either of the input is integer type & even if we give the output variable as a float then also we get the output as 6! What's the reason...?
The result is computed first, then assigned into whatever variable you want. So first, 37/6 yields 6, then it gets assigned to your float variable as a float, 6.0. It does become a float, but a 6.0 float.
The modulus operator gives you the remainder of a division. The number 1 divided by 3 gives you a result of 0 and left over of 1. The left over is the answer to the modulus. Hence the result is one.
Thank of it like that, how many perfect 2s can you take away from 10? That’s 10 2s, with nothing left to take away. But when it come to 2%10 how many 10s can you take away from 2 before you can’t anymore? That’s zero, but the remainder is 2 left. So for 5%3 that’s 2 because you can only take away three from five once, and that remaining is 2, that’s why one number up meaning 6 % 3 is 0 because it adds 1more to that remainder of 2 turning it into a three and now you have nothing left as a remainder 6%3 = 0 Use that for all of them 11%2 = 1 10%2 = 0
As a beginner, i found it quite useful. thumbs up!
6:02 Perfect explanation
That was quite literally the best explanation ever for this type of operator. I literally had a "Holy Fuck....That's Awesome moment!
With that week as an example , you gave a nice explanation.
The best explanation of mod(%) with it's use.
Thanks for understandable language u speak
bro just loved the way u explained
exactly what i was missing. thanks
really clean explanation.
If you can't understand why we use % to get a number less than the one we want it's because if you divide by 3 for example you have to get a number less than 3 because if a number equal to 3 or more existed than 3 would divide it, so it wouldn't be possible for example 12 / 3 = 4 because we can no longer divide by 3 and there is no remainder so it's 4 if there was a remainder that would be the % and the remainder can't be 3 because then the result will be more than 4 . It took me some time to get that, thank you God.
perfect explanation, thanks a lot!
Thank you so much!
This really helped👏🏽
Thank you this makes so much more sense. Even Full Sail couldent explain it to me right lmao.
Glad to be of help!
This is what i missed before 😀.. thanks a lot
Great explanation bro ty
You forgot to mention that it's often used to check if a number is odd or even.
if (myInteger % 2 == 0)
std::cout
Thank u
thank youuu!!
Nice helpfull
👌👌
floats uses fmodf?
Im that guy that would type 10 on your program lol
Thanks for the explanation though.
😅
what happens to the modulus when the numerator is bigger than the denomerator
The modulus operator gives you the remainder of a division. The result will always be 1 less than the denominator. So you have to see how many times does the denominator "fit" inside the numerator. Whatever is left over is your result. You just have to carry out the division.
3%7 ??? Answer?
3
why cant i do x = a%b/c??
What is x, a, b, and c? What error are you getting?
Try giving 37/6 the result v get is 6 what's the reason!?
An operation gives a result on the same data type as its operands. Both 37 and 6 are integers, so your result has to be an integer. 37/6 = 6.16666..., but because it has to be an integer, you lose the fraction part, 6.
@@VelcodeCS yeah but,either of the input is integer type & even if we give the output variable as a float then also we get the output as 6! What's the reason...?
The result is computed first, then assigned into whatever variable you want. So first, 37/6 yields 6, then it gets assigned to your float variable as a float, 6.0. It does become a float, but a 6.0 float.
To properly compute that operation, you have to turn your operands as floats. Either 37.0/6, 37/6.0, or 37.0/6.0.
Why 1 % 3 is equal to 1 ???
The modulus operator gives you the remainder of a division. The number 1 divided by 3 gives you a result of 0 and left over of 1. The left over is the answer to the modulus. Hence the result is one.
When 10%2 = 0, then why 2%10 = 2? why not 0? 2%10 gives the remainder "0" not "2" - Do anyone has a solid explanation?
10 / 2 = 5 with a remainder of 0.
2 / 10 = 0 with a remainder of 2.
The order of these matter. I hope it helps.
Thank of it like that, how many perfect 2s can you take away from 10? That’s 10 2s, with nothing left to take away.
But when it come to 2%10 how many 10s can you take away from 2 before you can’t anymore? That’s zero, but the remainder is 2 left.
So for 5%3 that’s 2 because you can only take away three from five once, and that remaining is 2, that’s why one number up meaning 6 % 3 is 0 because it adds 1more to that remainder of 2 turning it into a three and now you have nothing left as a remainder 6%3 = 0
Use that for all of them
11%2 = 1
10%2 = 0
Shouldn't the answer be Tuesday? As the count here starts from 0, Sunday.
Yeah but it starts from 0 that is Sunday and recounts sunday again so it has the number 7, Monday 8, Tuesday 9, Wednesday 10
3%5 then what reminder
3
How the result is 3 @@VelcodeCS