Recognizing when to use the modulus operator

前端 未结 19 806
醉梦人生
醉梦人生 2020-11-29 16:40

I know the modulus (%) operator calculates the remainder of a division. How can I identify a situation where I would need to use the modulus operator?

I know I can u

相关标签:
19条回答
  • 2020-11-29 17:14

    Imagine that you have an elapsed time in seconds and you want to convert this to hours, minutes, and seconds:

    h = s / 3600;
    m = (s / 60) % 60;
    s = s % 60;
    
    0 讨论(0)
提交回复
热议问题