douxiongzhen2126 2016-10-31 15:42
浏览 75
已采纳

编程概念:将一个数字拆分成其他整数的组是什么?

I know there must be an official name to this but unfortunately I have forgotten the term. I have an integer which changes, lets say its 10. I want to divide this into however many groups as long as the result in each of the groups is 3. The leftover group if its not 3 should be 1 or 2 as I am only using whole numbers.

I also want to check this every 3 iterations but from the start so the non 3 comes at the end, so for 10

number = 3, $tag = col-md-4

number = 3, $tag = col-md-4

number = 3, $tag = col-md-4

number = 1, $tag = col-md-12

sorry if this is trivial

  • 写回答

1条回答 默认 最新

  • doudu6100 2016-10-31 22:32
    关注

    I think you are thinking of modulo (php modulo operator %)? It provides the remainder after performing division. For example:

    Division:

    10 / 3 = 3.333...
    

    Modulo:

    10 % 3 = 1
    

    In programming use, you can use the floor of the first (division) operation to get the number of full groups, and the modulus to get the size of the last group.

    For example, if you start with 14:

    How many groups of 3?

    floor(14 / 3) = 4
    

    How many in last group?

    14 % 3 = 2
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮