+ 1

Write a java program to output the combination of natural numbers, which add up to a given number e.g 27->2+3+4+5+6+7,8+9+7.etc

You can also post code in other languages...THE NUMBERS MUST BE CONSECUTIVE

17th Nov 2016, 1:29 PM
Harshit Sharma
Harshit Sharma - avatar
5 Respostas
+ 1
public int add(int n) { int sum; for(int i = 1; i <= n; i++) { sum += i; } return sum; } You have only to call this function in your main function.
17th Nov 2016, 7:24 PM
Volts
Volts - avatar
+ 1
What do you mean ? Call it in the main function ?
18th Nov 2016, 7:46 PM
Volts
Volts - avatar
+ 1
to see the answer see my code section
22nd Nov 2016, 6:09 AM
Harshit Sharma
Harshit Sharma - avatar
0
Dear volts , Complete other steps also
18th Nov 2016, 6:31 AM
Harshit Sharma
Harshit Sharma - avatar
0
you have to display the number of possible ways in which a number can be represented as a sum of consecutive natural numbers e.g. if you input 27 then output will be 2+3+4+5+6+7 8+9+10 13+14 all of which have sum equal to 27
19th Nov 2016, 3:13 AM
Harshit Sharma
Harshit Sharma - avatar