I’ve written this code for sub-arrays, its giving correct subarrays but there are some extra elements also in the output. https://ide.codingblocks.com/s/36244
Code for subarrays
Your answers are being repeated k times. Why have you made an extra for loop outside. This causes repeated answers. You just need 2 nested for loops and not 3.
Could you please do necessary changes in the program? I’m not able to get a correct answer with 2 loops.
Could you please do necessary changes in the program? I’m not able to get a correct answer with 2 loops.
https://ide.codingblocks.com/s/36553
I’ve made changes in your code.
Now it solves problem in 2 loops, and the answers are not repeated.
It doesnt give correct output.
output for subarrays should be:
1 12 123 1234
2 23 234
3 34
4
Earlier your code gave repeated answers and didn’t gave all the answers. I made changes in your code just to remove the repeated answers. You have to think how to include the answers which are not being displayed.
It is very simple.
hint : make loop of i from 0 to n-1 and of j from i to n-1 as you can observe from the correct output you wrote.
comment down the 14 line