7 kyu

Simple Fun #181: Rounding

276 of 669myjinxin2015

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 Trained1336
Total Skips19
Total Code Submissions4409
Total Times Completed669
JavaScript Completions274
PHP Completions68
C# Completions73
Python Completions276
Ruby Completions40
Total Stars16
% of votes with a positive feedback rating88% of 202
Total "Very Satisfied" Votes164
Total "Somewhat Satisfied" Votes28
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