Hello, can anyone clarifies this? I need to find consecutive segments that are odd or even. For example

2 6 5 = 2 and 6 = 2 consecutive even integers | 1 odd
4 6 8 1 3 = 4, 6, and 8 = 3 consecutive even integers | 1 and 3 consecutive odd integers 2
1 2 4 5 = 2 and 4 = 2 consecutive even integers | 1 odd
1 3 5 7 2 1 4 3 = 4 consecutive odd integers | 1 even

Recommended Answers

All 5 Replies

What would you expect as a result for the following sequence of integers?
1 2 3 6 7 8 11

Your last exampe, 1 3 5 7 2 1 4 3 is incorrect. It should be 4 odd, 2 even, 1 odd, 1 even, 1 odd.

And to answer niranga's question, the answer should be 1 odd, 1 even, 1 odd, 1 even, 1 odd, 1 even, 1 odd... :-)

@rubberman
why is it 2 even? in 1 3 5 7 2 1 4 3
4 odd,2 even,1 odd,1 even,1 odd

for me this should be

1,3,5,7 = 4 odd
2 = 1 even
1 = 1 odd
4 = 1 even
3 = 1 odd

@niranga
1 2 3 6 7 8 11
1 = 1 odd
2 = 1 even
3 = 1 odd
6 = 1 even
7 = 1 odd
8 = 1 even
11 = 1 odd

thanks for your replies

So sorry for the late reply :-/
@rubberman: Thanks for the comment :)
@iceparticle.com : Did you manage to solve this?

INput all numbers to an array and then for each element check if it is odd or even.Then check if the next is of same category using a loop until a mismatch is found. Use a counter to count no of consecutive odds or evens. Then after a mismatch is found, Output as per your requirement and then resume the loop from where you found the mismatch. I hope this helped.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.