cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
question about arrays
question about arrays
Apr 16, 2012 at 7:58pm UTC
malakian
(2)
Hi! I've been dealing with this problem for a couple of hours, maybe you can hel p me:
I have an array of "1" and "0" like this one:
01100111100
And I need to say how many groups of numbers "1" there are, in this case the answer is 2.
I've tried with a while cicle inside a for cicle but it didn't work.
Thank you!
Apr 16, 2012 at 8:28pm UTC
LB
(13399)
Add a zero to the beginning and loop through them all. Every time you see a 01 pair add one to the total count. Remember to increment by one, not two, and be careful not to go out of bounds (eg start at 1 and check at index and index-1)
Apr 16, 2012 at 9:02pm UTC
malakian
(2)
Thank you!! that worked perfectly!!
Topic archived. No new replies allowed.