Rounding up a number to nearest multiple of 5

后端 未结 21 2011
感动是毒
感动是毒 2020-11-27 15:24

Does anyone know how to round up a number to its nearest multiple of 5? I found an algorithm to round it to the nearest multiple of 10 but I can\'t find this one.

T

21条回答
  •  醉话见心
    2020-11-27 16:11

    int round(int num) {
        int temp = num%5;
        if (temp<3)
             return num-temp;
        else
             return num+5-temp;
    }
    

提交回复
热议问题