A 2D array would probably help here to simplify the math (you can use a 1D array but the math will be a bit more involved to properly calculate indices), as well as recursion.
If you were to do that, you would have
Click on a number. For this example, the user clicked on Grid[0][2], which is the first row, third column (the first 1).
Then, simply run a recursive algorithm on the clicked tile and its adjacent neighbor in each cardinal direction that detects if any of the connected tiles are a 1. If they are, run the recursive algorithm on that tile. Repeat until the algorithm no longer runs. As you do this, store all the 1s in a table, and you have a table of all of the connected 1s.