# help with "shrinking" array

• 05-11-2007
believe
help with "shrinking" array
i need help writing a program for a "shrinking array". i have no idea where to start and urgently need to know this for a class...

the question is something like this.

if you have a large array say:
0 1 2 4 5 7 5 4 2 1 0
1 2 3 5 6 8 6 5 3 2 1
2 3 4 6 7 9 7 6 4 3 2
4 5 6 8 9 11 9 7 6 5
etc (more numbers)

you want it to be "shrunken" into a array like this:
2 4 6 4 2
4 7 9 7 4
6 9 11 9 6
4 7 9 7 4
2 4 6 4 2

where the numbers in the shrunken array are the averages of a 3x3 from the large matrix. Ie the 2 in the top corner of the shruken array is found by:
(0+1+2+1+2+3+2+3+4)/9. this similar work is done for the numbers found in the shrunken array.

the question asks to write a function that has a symbolic constant SIZE that represents the number of rows and columns in the larger array. and that SIZE will always be odd and greater than or equal to 3. This function must work for any original image of dimensions SIZE by SIZE and must accept the larger source array and the smaller target array as arguements.

it also says not to use any printf(" or scanf(" statements.

thanks for your help guys, any is appreciate... i am desperate in searching for a solution for this (even though i have no idea where to start).
• 05-11-2007
KONI
And what have you come up with so far ?
• 05-11-2007
Unfortunately, we're not likely to just code up a homework assignment for you.

I'd suggest working this out on paper, by hand, for a few minutes, and see how YOU would do it. Then, expand what your doing into a step by step procedure. Then flush that out (forgetting the details for now), and put down some pseudo code for your algorithm.

There are others ways to print output besides printf - like putchar() or fprintf(stdin, ...).
What does your instructor WANT you to use? Or is that part of the assignment challenge?

For doing the arithmetic, a basic pair of loops should suffice:

Code:

for (row = 0; row < rowNum; row++)  {
for (col = 0; col < colNum; col++)  {
/* you'll need a number of special handling if statements to keep your row and col
variables from running off the array. All the subscripts on the edges of the array are
the problem.
*/
/* normal interior of the array code (sa=small array, ba = big array*/
sa[row][col] = ba[row][col - 2 + ba[row][col - 1] + ba[row]col] + etc.
}
}

These kinds of assignments will take longer than expected, so don't put it off! Show us some work, and then, show us some code.