CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

# Thread: how to count contiguous and common zeros in various arrays

1. Junior Member
Join Date
May 2014
Posts
1

## how to count contiguous and common zeros in various arrays

Hi Friends!

If I have number of arrays(its 3 for instance and may vary) with fixed size (15), it consist of zeros and non-zeros

How to write a program to count the common zero sequences and there indexes of arrays?

eg:array1[15]={5,5,0,0,4,4,4,0,0,0,1,0,0,0,3}

array2[15]={1,0,0,0,0,7,7,0,0,3,0,0,0,0,2}

array3[15]={6,6,6,0,8,8,8,0,0,0,3,3,0,0,4}

...........

sample output for the above arrays:

Index==> Nim_of_zeros

3==> 1

7==> 2

12==> 2

2. Banned
Join Date
Aug 2013
Posts
55

## Re: how to count contiguous and common zeros in various arrays

Originally Posted by shel88
How to write a program to count the common zero sequences and there indexes of arrays?
You can start by writing a program that can do that for one array. When that works you expand the program to handle several arrays.

If you can check whether a position is zero in one array it's not hard to check whether that position is zero in all of several arrays.

3. ## Re: how to count contiguous and common zeros in various arrays

Create summary array which contains sum of total values of input arrays in every position. Count contiguous zeros in it. Algorithm for one array is trivial.
The point here is that summary array has 0 in position i, only of all input arrays have 0 in this position.
Last edited by Alex F; May 12th, 2014 at 03:55 AM.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•