0

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.

3
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by warpstar
0

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
0

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
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.