Given a number N. The task is to print all possible sums of consecutive numbers that add up to N.
Examples :
Input : 100
Output :
9 10 11 12 13 14 15 16
18 19 20 21 22
Input :125
Output :
8 9 10 11 12 13 14 15 16 17
23 24 25 26 27
62 63
Recommended: Please try your approach on {IDE} first, before moving on to the solution.
One important fact is we can not find consecutive numbers above N/2 that adds up to N because N/2 + (N/2 + 1) would be more than N. So we start from start = 1 till end = N/2 and check for every consecutive sequence whether it adds up to N or not. If it is then we print that sequence and start looking for the next sequence by incrementing start point.
references
Code:
TRy This Problem:
0 Comments
If you have any doubts, Please let me know