Consecutive Sums
Explore how to use nested loops and array methods in Ruby to find all possible consecutive natural number sums for a given number. This lesson helps you practice looping concepts and output formatting for problem solving.
Problem
Some natural numbers can be written as a sum of consecutive natural numbers. For example:
Some can be written in more than one way. For example:
Write a program to output all possible ways ...
Enter a number: 99 = 2 + 3 + 49 = 4 + 5
Finding consecutive numbers that sum to a target number
Purpose
Loop within another loop with ...