[an error occurred while processing this directive]
CMSC201 Programming Hint
Overall approach to the problem
Think about the overall structure of your program.
- You have to process each image in the input -- that's one
loop. To process an image you have to:
- Process each row in the image -- that's a second loop nested in
the first. To process a row you have to:
- Process each pixel in the row -- that's a third loop nested in
the second.
So expect to have three nested loops. What kind of loops -- for loops
or while loops? For loops usually involve using an index variable as
a counter which is incremented or decremented for each iteration until
a special value is reached. A while loop is more general -- involving
a condition which is checked as each iteration begins until it becomes
true (e.g., a sentinel value was read). Or you can use a while loop
with a TRUE condition, recognize when the loop should end inside the
loop and force termination with a break.
Once you have the basic structure for your loops you can figure out
how to keep track of the other items, such as the number of pixels in
each image and their average values. Where should the variables for
these two things be initialized? Where should they be updated? Where
should this information be printed?
Try your program on the simplest data first. Know what the right
answer should look like. Make up your own test data if necessary.
When it is working for that, try it on more complicated data.
[an error occurred while processing this directive]
Monday, 26-Feb-1996 19:47:35 EST