compute the average of each row and column

This is a discussion on compute the average of each row and column within the C Programming forums, part of the General Programming Boards category; i need to create a function to the program i've written which takes the two-dimensional array and returns an array ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    4

    Question compute the average of each row and column

    i need to create a function to the program i've written which takes the two-dimensional array and returns an array "r" (of length 4) and "c" (of length 3). This function should computer the average values of each row and column, then return r and c to main program. both array need to be double precision. Here is the code of the main function, it just created a two-dimensional array of size 4x3 and is initialized to the sum of x, the row, and column values:

    Code:
    # include <stdio.h>
    
    void mavg(int m[][3]);
    
    int main(void)
    {
      int x;
      int i, j;
      int m[4][3];
    
      /* Part 1 */
      printf("Enter an integer x: ");
      scanf("%d", &x);
    
      /* Part 2 */
      for(i=0; i<4; i++){
        for(j=0; j<3; j++){
          m[i][j] = i+j+x;
          printf(" %d", m[i][j]);
        }
      printf("\n");
      }
    
      mavg(m); 
    
    return 0;
    }
    
    void mavg(int m[][3])
    {
      int r[4];
      int c[3];
    
      int sum, row, x, y, avg;
    
      sum = 0;
      row = 0;
    
    
    
    }
    Last edited by rasiegel; 04-03-2011 at 05:50 PM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    1. Go read the thing on the forum that said << !! Posting Code? Read this First !! >>
    2. Come back to your first post and press Edit.
    3. Find the start of your code and right before it, add: [code]
    4. Find the end of your code and right after it, add: [/code]
    5. Press save.
    6. Go read the homework policy sticky as well.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    When you edit it to fix the code with code tags, add in what it is that has you stumped at the moment.

    Posts without questions, don't get many answers - and Welcome to the forum, Rasiegel!

  4. #4
    Registered User
    Join Date
    Feb 2011
    Posts
    4
    i need to figure out how to pass an array to a function and how to make a for statement to add the rows and columns thanks

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    This should get you started on loops: Cprogramming.com Tutorial: Loops
    As for how to pass an array:
    Code:
    void foo( type array[], int size );
    ...
    type array[ 4 ];
    ...
    foo( array, 4 );
    That should give you the general idea.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 03-02-2011, 06:35 PM
  2. Trouble with two two dimensional arrays
    By scmurphy64 in forum C Programming
    Replies: 5
    Last Post: 12-06-2009, 05:57 PM
  3. background ascii color
    By dvsumosize in forum C Programming
    Replies: 0
    Last Post: 11-09-2009, 10:19 AM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 08:32 AM
  5. Is there a bug in this part of my algorithm for connect 4?
    By Nutshell in forum Game Programming
    Replies: 8
    Last Post: 04-28-2002, 01:58 AM

Tags for this Thread


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