#include <stdio.h>
/*
next_multiple_of_10:
--------------------
Returns the next multiple of 10 greater than or equal to n.
Algorithm:
- Add 9 to n: this ensures that any number not already a multiple of 10
will "spill over" into the next multiple when integer-divided by 10.
- Divide by 10: integer division truncates toward zero.
- Multiply by 10: reconstruct the multiple of 10.
Example:
n = 23 → (23 + 9) = 32 → 32 / 10 = 3 → 3 * 10 = 30
n = 40 → (40 + 9) = 49 → 49 / 10 = 4 → 4 * 10 = 40
*/
int next_multiple_of_10(int n) {
return ((n + 9) / 10) * 10;
}
/*
main:
-----
Demonstrates the function with a sample input.
*/
int main(void) {
int nums[] = {23, 10, 0, 1841, 1};
int length = sizeof(nums) / sizeof(nums[0]);
for (int i = 0; i < length; i++) {
printf("%d\n", next_multiple_of_10(nums[i]));
}
return 0;
}
/*
run:
30
10
0
1850
10
*/