Want to print sum of n natural numbers in Ruby? In this example, we have shared a ruby program to print sum of n natural numbers.
# Ruby program to print sum of n natural numbers.
puts "Enter a number:"
input = Integer(gets.chomp)
result = input * (input + 1) / 2
Enter a number:
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.