How to Return the Closest Number Multiple of 10 in C
The challenge Given a number return the closest number to it that is divisible by 10.
Example input:
1 2 3 22 25 37 Expected output:
1 2 3 20 30 40 The solution in C Option 1:
1 2 3 4 5 #include <math.h> int round_to_10 (int n) { return round(n / 10.0) * 10; } Option 2:
1 2 3 int round_to_10(int n) { return (n + 5) / 10 * 10; } Option 3: