Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int round_to(int original, int to)
- {
- int mod = original % to;
- float to_half = to / 2.0f;
- if (mod < to_half)
- {
- return original - mod;
- }
- else
- {
- return original + (to - mod);
- }
- }
- int main()
- {
- int i;
- for (i = 0; i < 30; i++)
- {
- printf("%d -> %d\n", i, round_to(i, 5));
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement