brewersfan1976

sum_of_multiples.rb

Mar 1st, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.15 KB | None | 0 0
  1. def sumOfMultiples(n, k)
  2.     sum = 0
  3.     x = k
  4.    
  5.     while (x <= n)
  6.           sum = sum + x
  7.           x = x + k
  8.     end
  9.    
  10.     return sum
  11. end
Advertisement
Add Comment
Please, Sign In to add comment