简体   繁体   中英

If value is greater than 10, process that value by each 10 with one function, and the remainder of the value with another function

I'm looking for a solution to this problem: I want to check, if a value is greater than 10, then process that value by each 10 with one function, and the remainder of the value, which is then less than 10, with another function. It would have to take each 10 into the account, as well as the remainder; (preferably with no rounding, so its exact and precise; and preferably as fast for the cpu as possible).

Thank you for your help

int tens = n / 10;             // get number of 10s in n
int units = n % 10;            // get remainder (0..9)

for (i = 0; i < tens; ++i)
    do_tens_stuff();

for (i = 0; i < units; ++i)
    do_units_stuff();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM