1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
// 55, m=10, 50
// 57, m=5 55
int _round_down(int n, int multiple_of) {
assert(multiple_of != 0);
int n_rounded_down = (n / multiple_of) * multiple_of;
assert ((n_rounded_down % multiple_of) == 0);
return n_rounded_down;
}
int main(int argc, char* argv[]) {
printf("55 rounded down to the nearest 10 is %d\n", _round_down(55, 10));
printf("57 rounded down to the nearest 5 is %d\n", _round_down(57, 5));
printf("57 rounded down to the nearest 0 is %d\n", _round_down(57, 0));
return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
|
© Copyright 2022 Alexander J. Quinn This content is protected and may not be shared, uploaded, or distributed.