Heres the problem, Ill try my best to explain this: If your given a 5x5 array whicih looks like:

1 1 1 1 1
0 1 1 1 1
0 0 1 1 1
0 0 0 0 1
0 0 0 0 0

Basically in each column below any 1 is a set of zeros. What they want us to do is create a new array which will store the position where u hit ones in each ROW. For the example above it would be like

1
2
3
5
6 (if its all zeroes then we just assume after 6 zeros it would hit a 1)

So this array (1,2,3,5,6) would be printed on the screen. Any idea how i would do this? This is a sample midterm question which is not worth any marks so please if you can put any code watsoever will help.

Member Avatar for iamthwee

No! Do your own homework or provide some code you have tried for us to look at.

It's a 2-D array, presumably. Start from the top and go along each row and record the position of the first one.

Pseudo code:

loop y=0, 5
  loop x=0, 5
    if val of array[y][x] is 1
      print (x+1)
      break loop
  end loop x
end loop y

Thanks alot twomers!

It's a 2-D array, presumably. Start from the top and go along each row and record the position of the first one.

Pseudo code:

loop y=0, 5
  loop x=0, 5
    if val of array[y][x] is 1
      print (x+1)
      break loop
  end loop x
end loop y
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.