To find the possible consecutive natural no.s which when added, give user-entered no.
The question states : "Write a program which inputs a positive natural number N and prints the possible consecutive number combinations, which when added give N".
For example :
2 3 4
2 3 4 5 6 7
8 9 10
Here's my source code :
void main()throws IOException
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
System.out.println("Enter a Number:");
int arr=new int[N];
for(int i=0; i<N; i++)
for(f=0; f<N; f++)
for(r=f; r<N; r++)
for(int k=f; k<r; k++)
It accepts the number but gives no output.
Can you please verify the errors, correct it, and tell me where I went wrong.
Re: To find the possible consecutive natural no.s which when added, give user-entered
That's not how this work. I recommend you read through this: http://www.javaprogrammingforums.com...e-posting.html as well as the link in my signature on asking questions the smart way.
Originally Posted by amandeshmukh5
Also, you should try stepping through this with a debugger, or at least adding some more print statements, to figure out what's going on in your program.