Monday, August 19, 2013

Coderbyte: Simple Adding (Ruby)

PROBLEM

Have the function SimpleAdding(num) add up all the numbers from 1 to num. For the test cases, the parameter num will be any number from 1 to 1000.

SOLUTION

def SimpleAdding(num)
    total = 0
    1.upto(num) do |number|
        total +=  number    
    end
    return total
end

print SimpleAdding(STDIN.gets)