help with "shrinking" array

This is a discussion on help with "shrinking" array within the C Programming forums, part of the General Programming Boards category; i need help writing a program for a "shrinking array". i have no idea where to start and urgently need ...

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    10

    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).

  2. #2
    Lean Mean Coding Machine KONI's Avatar
    Join Date
    Mar 2007
    Location
    Luxembourg, Europe
    Posts
    444
    And what have you come up with so far ?

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 08:25 PM
  2. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  3. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 08:31 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 08:48 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21