7 kyu

Simple Fun #181: Rounding

257 of 636myjinxin2015

Description:

Task

Round the given number n to the nearest multiple of m.

If n is exactly in the middle of 2 multiples of m, return n instead.

Example

For n = 20, m = 3, the output should be 21.

For n = 19, m = 3, the output should be 18.

For n = 50, m = 100, the output should be 50.

Input/Output

  • [input] integer n

1 ≤ n < 10^9.

  • [input] integer m

3 ≤ m < 109.

  • [output] an integer
Fundamentals

Stats:

CreatedMar 6, 2017
PublishedMar 6, 2017
Warriors Trained1273
Total Skips19
Total Code Submissions4263
Total Times Completed636
JavaScript Completions257
PHP Completions66
C# Completions70
Python Completions263
Ruby Completions40
Total Stars14
% of votes with a positive feedback rating88% of 197
Total "Very Satisfied" Votes160
Total "Somewhat Satisfied" Votes27
Total "Not Satisfied" Votes10
Total Rank Assessments9
Average Assessed Rank
7 kyu
Highest Assessed Rank
7 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • smolen Avatar
  • tachyonlabs Avatar
  • hobovsky Avatar
  • Fuzzi Avatar
  • Just4FunCoder Avatar
  • saudiGuy Avatar
Ad