Skip to content

Instantly share code, notes, and snippets.

@ph3nx
Last active January 3, 2016 16:29
Show Gist options
  • Save ph3nx/8490114 to your computer and use it in GitHub Desktop.
Save ph3nx/8490114 to your computer and use it in GitHub Desktop.
Ruby program that asks the user for a number and prints the sum of the numbers 1 to the number he chose.
def sum_to
print 'Enter any number greater than 1: '
input = gets.to_i
sum = 0
for a in 1..input do
sum += a
end
sum
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment