Last active
January 3, 2016 16:29
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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