brewersfan1976

sum_of_divisors.rb

Jun 25th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.22 KB | None | 0 0
  1. def sumOfDivisors(n)
  2.     x = 1
  3.     sum = 0
  4.    
  5.     while (x <= n)
  6.           if n % x == 0 then
  7.              sum = sum + x
  8.           end
  9.              
  10.           x = x + 1
  11.     end
  12.        
  13.     return sum
  14. end
Advertisement
Add Comment
Please, Sign In to add comment