+ 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

5 Réponses

+ 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.

+ 1

What do you mean ? Call it in the main function ?

+ 1

to see the answer see my code section

0

Dear volts , Complete other steps also

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