约数求和

def divisors(n)
  sumOfDivisors=0
  i=1
  while i<n
  if n%i==0
    divisor=i
    sumOfDivisors=sumOfDivisors+divisor
  end
  i=i+1
end
puts "The sum of divisors is "+sumOfDivisors.to_s
end

编程技巧