Learn Programming with C++ - Modulus Operator

แชร์
ฝัง
  • เผยแพร่เมื่อ 25 ธ.ค. 2024

ความคิดเห็น • 46

  • @kinzamir6450
    @kinzamir6450 3 ปีที่แล้ว +19

    As a beginner, i found it quite useful. thumbs up!

  • @radhakrishnant7519
    @radhakrishnant7519 3 ปีที่แล้ว +13

    6:02 Perfect explanation

    • @bladelazoe
      @bladelazoe ปีที่แล้ว +1

      That was quite literally the best explanation ever for this type of operator. I literally had a "Holy Fuck....That's Awesome moment!

  • @ms-hi2cc
    @ms-hi2cc 3 ปีที่แล้ว +3

    With that week as an example , you gave a nice explanation.

  • @rakibrafi3491
    @rakibrafi3491 9 หลายเดือนก่อน

    The best explanation of mod(%) with it's use.

  • @tejasbomble2659
    @tejasbomble2659 7 หลายเดือนก่อน +1

    Thanks for understandable language u speak

  • @muhammadharis-mr1js
    @muhammadharis-mr1js ปีที่แล้ว

    bro just loved the way u explained

  • @eqfrombc
    @eqfrombc 2 ปีที่แล้ว +1

    exactly what i was missing. thanks

  • @felathar1985
    @felathar1985 3 ปีที่แล้ว +2

    really clean explanation.

  • @MuslimMan377
    @MuslimMan377 2 ปีที่แล้ว +2

    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.

  • @Jackson_Nana
    @Jackson_Nana 7 หลายเดือนก่อน

    perfect explanation, thanks a lot!

  • @stormyknight427
    @stormyknight427 หลายเดือนก่อน

    Thank you so much!

  • @buhlehlengi3391
    @buhlehlengi3391 2 ปีที่แล้ว

    This really helped👏🏽

  • @bensmash03
    @bensmash03 2 ปีที่แล้ว

    Thank you this makes so much more sense. Even Full Sail couldent explain it to me right lmao.

    • @VelcodeCS
      @VelcodeCS  2 ปีที่แล้ว

      Glad to be of help!

  • @ikazodba
    @ikazodba 3 ปีที่แล้ว

    This is what i missed before 😀.. thanks a lot

  • @carlitodidthat
    @carlitodidthat 3 ปีที่แล้ว +1

    Great explanation bro ty

  • @zdspider6778
    @zdspider6778 ปีที่แล้ว +1

    You forgot to mention that it's often used to check if a number is odd or even.
    if (myInteger % 2 == 0)
    std::cout

  • @MmMmm-iz9mz
    @MmMmm-iz9mz 2 ปีที่แล้ว +1

    Thank u

  • @ellasandra8350
    @ellasandra8350 2 ปีที่แล้ว

    thank youuu!!

  • @amansingh.h716
    @amansingh.h716 ปีที่แล้ว

    Nice helpfull

  • @shahidjaved2867
    @shahidjaved2867 ปีที่แล้ว

    👌👌

  • @justaszakarauskas6068
    @justaszakarauskas6068 10 หลายเดือนก่อน

    floats uses fmodf?

  • @Perceptionz_Sound
    @Perceptionz_Sound 2 ปีที่แล้ว +1

    Im that guy that would type 10 on your program lol
    Thanks for the explanation though.

  • @jim2carol623
    @jim2carol623 2 ปีที่แล้ว

    what happens to the modulus when the numerator is bigger than the denomerator

    • @VelcodeCS
      @VelcodeCS  2 ปีที่แล้ว

      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.

  • @SANETWORK786
    @SANETWORK786 ปีที่แล้ว +1

    3%7 ??? Answer?

  • @thesumofmeandyou4175
    @thesumofmeandyou4175 3 ปีที่แล้ว

    why cant i do x = a%b/c??

    • @VelcodeCS
      @VelcodeCS  3 ปีที่แล้ว

      What is x, a, b, and c? What error are you getting?

  • @tejasteju1251
    @tejasteju1251 3 ปีที่แล้ว

    Try giving 37/6 the result v get is 6 what's the reason!?

    • @VelcodeCS
      @VelcodeCS  3 ปีที่แล้ว +2

      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.

    • @tejasteju1251
      @tejasteju1251 3 ปีที่แล้ว

      @@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...?

    • @VelcodeCS
      @VelcodeCS  3 ปีที่แล้ว +1

      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.

    • @VelcodeCS
      @VelcodeCS  3 ปีที่แล้ว +1

      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.

  • @rubenmocan2179
    @rubenmocan2179 2 ปีที่แล้ว

    Why 1 % 3 is equal to 1 ???

    • @VelcodeCS
      @VelcodeCS  2 ปีที่แล้ว +2

      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.

  • @yasirzubair20
    @yasirzubair20 2 ปีที่แล้ว

    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?

    • @VelcodeCS
      @VelcodeCS  2 ปีที่แล้ว +2

      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.

    • @Import_success
      @Import_success 2 ปีที่แล้ว

      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

  • @Nikola95inYT
    @Nikola95inYT ปีที่แล้ว

    Shouldn't the answer be Tuesday? As the count here starts from 0, Sunday.

    • @Edme-uw6gr
      @Edme-uw6gr 3 หลายเดือนก่อน

      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

  • @aminakhurshid3340
    @aminakhurshid3340 3 ปีที่แล้ว

    3%5 then what reminder