C Programming Tutorial 32 - Modulus Operator

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

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

  • @codebreakthrough
    @codebreakthrough  6 ปีที่แล้ว +6

    Learn Javascript - bit.ly/JavaScriptPlaylist
    Learn Java - bit.ly/JavaPlaylist
    Learn C# - bit.ly/CSharpTutorialsPlaylist
    Learn C++ - bit.ly/CPlusPlusPlaylist
    Learn C - bit.ly/CTutorialsPlaylist

  • @mcmihion8657
    @mcmihion8657 6 ปีที่แล้ว +56

    After the words of wisdom...I'm 39, starting c for scratch. It's never too late.

    • @lilcrisjan
      @lilcrisjan 5 ปีที่แล้ว +9

      I hope you're still doing it sir! I couldn't afford college but yes it's always never too late!

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

      34 here :)

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

      35!

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

      Going back to university at 40 for a career change. I feel this.

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

      career change at 43! this has been awesome

  • @Nomuu
    @Nomuu 4 ปีที่แล้ว +8

    I am a first year student, because of this pandemic the way of learning is through online class but I’ve been struggling comprehending the c programming of how our professor teach it to us. I get really overwhelm of everything he teaches, because I don’t know a thing in programming.. watching your videos helps me understand little by little, I hope someday I can relate to what our professor is discussing.

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

    The pet rat pizza example is so golden!

  • @OsadeTOOT
    @OsadeTOOT 5 ปีที่แล้ว +4

    i gave myself this example: 13 % 3 is 1, because if all the 3 in 13 get eaten there will be 1 left
    there is four "3" inside 13
    1 is extra and it remains
    or 1 doesn't count as 3 so it remains

  • @MizManFryingP
    @MizManFryingP 5 ปีที่แล้ว +4

    Straight to the point with great visual explanations and a fun attitude.
    Fantastic tutorial Caleb, keep it up!

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

    On a clock with 2 hours, it ends up at 1 O'clock if 5 hours pass is how I remember what 5%2 means

  • @philipp9932
    @philipp9932 4 ปีที่แล้ว +3

    The pizza was a good example, however im hungry now

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

    Thankyou I haven't understood this for months and your pizza analogy really helped :)

  • @pablo-im6mr
    @pablo-im6mr ปีที่แล้ว +1

    If naay wmsu comsci nag tanaw ani ayaw kabalaka i explain ra nako unya sa school

  • @unboxmodz8584
    @unboxmodz8584 7 ปีที่แล้ว +10

    well you do good videos they help alot
    and i want to be a reverse engineer so yeah im still there learning C lol
    but with your videos ill learn Fast

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

    Modulus? More like modu-yay for us, because we’ve got such a great teacher. Thanks again for all of these wonderful videos!

  • @Tracks777
    @Tracks777 7 ปีที่แล้ว +7

    I enjoyed your video :) Keep it up!

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

    Actually there is a modulus operator in C instead of using % sysmbol Modulus is defined in stdlib.h file and the syntax goes like this:
    1) define the result like so:
    div_t result; /* Make sure #include is in the header */
    2) Then define your variables:
    int x = 45; int y = 4;
    result = div(x, y);
    3) Now print your results like so:
    printf("%4d DIV %d = %d
    ", x, y, result.quot);
    printf("%4d MOD %d = %d

    ", x, y, result.rem);
    This should work just fine.

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

    I loved it! And your comparison with pizza was a life savior for me. Thanks!!!

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

    "My illustrations are weird and awful sometimes" - says it after making us understand the concept by taking a simple real life example of pizza.

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

    i love you caleb curry great work..this series is awesome

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

    Great video and very easy to understand!

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

    Great educational video series, keep up the good work!

  • @iamzumie
    @iamzumie 4 ปีที่แล้ว +5

    Sharing your pizza with your pet rat, imagine that :D great content, very clear videos.

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

    You're making my journey of learning to code really fun !!! Thanks a lot for that.
    I laugh so hard when I watch your videos !!!

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

    Thank you! I understand now what and how modulus operator is and works.

  • @WarringFighter
    @WarringFighter 5 ปีที่แล้ว +5

    i guess this is what haha sounds like when someone texts it

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

    I just found out that the % operator in C isn't a modulo operator the hard way. I was writing a ceasar cipher program for fun and predefined in arrays what characters should be actually ciphered. So to put the right character into the output file according to the chosen key variable k, I
    fputc (arr[ (i - k) % 26], fp)
    and logically in my head everything should work fine. I took my calculator and checked quickly if this would behave mathematically like I expect and sure enough as long as the (i - k) part is calculated before the % operation negative numbers would result in the desired index number of the array, except it doesn't, because % is actually not a modulo operator in C it is the remainder operator. You might now say but isn't that the same and the answer is no. It took me literally hours to finally realize this. I was getting all kind of weird outputs and I checked every step of the code multiple times and I couldn't find the bug until I tested this stupid % operator more in depth. It doesn't like negative numbers it can't properly compute them. This is how I got to this video. Reading the C99 definition of the % operator finally confirmed my suspicion. Now I have to rewrite my code to handle this completely unexpected weirdness.
    Long story short, today I learned that the % operator is actually not a modulo but a remainder operator. The more you know xD

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

    Thank you. How we can translate this calculation to a math formula?

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

      I think the best way to describe it in C Programming is as a remainder. 5%2 = 5 - 2*truncate(5/2) = 5 - 2*2 = 1. Gets a bit weird with negative numbers though.

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

    So in C, mod isn’t fractional?
    In Desmos, if you plot
    y=mod(ax,b)
    you get a sawtooth with slope of a and period of b/a, and y has range [0,b)
    Is there a library or built-in function that allows fractional modulus?

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

    if i apply the modulus operator between 4 and 8 the remainder would be 0.5, but when I run the program the answer is 4, What is wrong with fractions?

    • @yassinehamza4300
      @yassinehamza4300 4 ปีที่แล้ว

      Modulus tells u the rest so 4%8 is 0 and the rest is 4

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

    I like your illustrations too bro, dont worry

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

    What I don't know if I understand is having a number like 25 being divided by 2, which gives you 12.5. Why does it give me 1 and not 12? I know I'm probably being dumb but I need help clearing this up.

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

    How to write a program that displays which numbers between 1 to 500, are divisible by a number an user inputs?

  • @joy-sm5sl
    @joy-sm5sl 4 ปีที่แล้ว

    well.. time is way more valuable than things but sometimes we don't appreciate time more than things hahah why am i commenting things like this in a programming video but anw tysm for your tutorials i'm learning c as a fresh college student, not knowing anything about c language and came across to your channel which i never regret. tysm (should i call you) sir caleb, bless you!

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

      These vids help inspire deep thoughts. It’s ok ♥️

    • @joy-sm5sl
      @joy-sm5sl 4 ปีที่แล้ว

      @@codebreakthrough HAHAH never imagined getting a reply from you! Such an honor🙏🏼 I've been learning through your videos these past days and they're sooo easy to understand and for me it's one of the best channels at teaching programming languages. Stay inspiring Caleb, i aspire you!

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

    your illustrations are not weird, thanks for the pizzaaa

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

    ez, just eat the remaining pizza without Pepper Jack knowing

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

    my teacher said to use %d for integers. do you know why? why are you using %i

  • @user2038-g6x
    @user2038-g6x 4 หลายเดือนก่อน

    Can I use modulus function with type long in c ??

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

    Yo' IDE too dark can't see clearly

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

    A. I am totally enjoying your c videos

  • @neonkuna7702
    @neonkuna7702 6 ปีที่แล้ว

    I want the modulus where the first number is smaller than the second number

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

    Can someone please explain what a modulator sign is? I'm so confused on how to work out a modulus operation

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

      I think that the percent sign % is commonly used to denote modular operations. Sometimes the word “mod” or “modulo” is used instead.

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

      But beware the % sign isn't actually a proper modulus operator in C, I learned this the hard way today, after bug tracking my code for over 3 hours.

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

    Also do for us when the numerator is less than the denominator

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

    why did you put the "i" after %

  • @ammarnadir7860
    @ammarnadir7860 7 ปีที่แล้ว

    what software do you use?

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

    very helpful, thank u!

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

    0:15 that Beavis and Butthead laugh :D

  • @theepicgamerpro3634
    @theepicgamerpro3634 6 ปีที่แล้ว +3

    thank you !

  • @jim0_o
    @jim0_o 4 ปีที่แล้ว

    So a integer of pizza is a piece...
    !! that must make a float of pizza be the slice.

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

    or c) I am a college student with a horrible profesor for programming and you are my only hope

  • @avdeshkumar8500
    @avdeshkumar8500 4 ปีที่แล้ว

    Hey Caleb I wanted to ask sumthing.... What if I were to enter
    " 55.5 %10" what result will I get.

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

    b) I'm a total geek and already know most of this stuff so I'm watching it at 1.5x speed

  • @askksn
    @askksn 6 ปีที่แล้ว +4

    why is 9%10 = 9?
    i can't wrap my head around this..lol
    btw nice video :)!

    • @shakefl
      @shakefl 6 ปีที่แล้ว +8

      10 doesn't go into 9 once, so the entire thing is the remainder. Think of it like division: 9 divided by 10. You'll be left with 9/10 or 0.9. Since it isn't greater than or equal to 1, 0.9 itself is the remainder.

    • @samadhistate9637
      @samadhistate9637 5 ปีที่แล้ว

      @@shakefl then why is 9 % 16 = 9? shouldn't it be 5625 (ie. 9/16 = 0.5625)

    • @shakefl
      @shakefl 5 ปีที่แล้ว

      ​@@samadhistate9637 Remember what I originally pointed out. 9 isn't greater than 16, so 16 can't be divided out of 9 (ie 16 is divided out 0 times). Thus the remainder is the original (9).

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

      @@samadhistate9637 9 is the remainder itself dingooo

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

    What is 2%5 ???

  • @Noah-qd4ts
    @Noah-qd4ts 4 ปีที่แล้ว

    thanks, helped a lot

  • @wokezombie8305
    @wokezombie8305 5 ปีที่แล้ว

    wise words, about time, agreed.

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

    Thank you a lot!

  • @alaaaltinawi4061
    @alaaaltinawi4061 5 ปีที่แล้ว

    what about the remainder of floating numbers

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

      They float off into the void, never to be seen again.

  • @gokulsai901
    @gokulsai901 4 ปีที่แล้ว

    #include
    int main() {
    int input=0;
    int output;
    printf("enter the number to find a factor of");
    scanf("%d",&input);
    for(int i=0;i

  • @brettsullivan7801
    @brettsullivan7801 6 ปีที่แล้ว +3

    Can you teach c+ and c++?

    • @min-juiyeh664
      @min-juiyeh664 6 ปีที่แล้ว +2

      and D?

    • @kzy747
      @kzy747 5 ปีที่แล้ว

      @@min-juiyeh664 and D++

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

    love you man

  • @ethanungar1589
    @ethanungar1589 5 ปีที่แล้ว

    i love your vids thank you

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

    great video

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

    Well done

  • @OsadeTOOT
    @OsadeTOOT 5 ปีที่แล้ว

    thanks

  • @marlondsanchez3239
    @marlondsanchez3239 5 ปีที่แล้ว

    Good video

  • @TaBi-0
    @TaBi-0 ปีที่แล้ว

    Jajakallahu khiran

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

    Is this an arithmetic and assignment operator? REPLY TO COMMENTS!!! LOL

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

      Sorry its arithmetic i didnt pay attention lol thx

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

    THANK CHU

  • @londonsystem6622
    @londonsystem6622 4 ปีที่แล้ว

    The Best

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

    died 0:45

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

    Your a funny dude ;)

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

    Am I the only one who got annoyed by the way he talks?

    • @codebreakthrough
      @codebreakthrough  4 ปีที่แล้ว

      🙋

    • @cankavas
      @cankavas 4 ปีที่แล้ว

      @@codebreakthrough You yourself huh, that was a smart answer :D

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

    Thank you!

  • @thatfeeling6917
    @thatfeeling6917 4 ปีที่แล้ว

    thanks

  • @walidsdd3398
    @walidsdd3398 4 ปีที่แล้ว

    Thank you!