average of array elements?

This is a discussion on average of array elements? within the C Programming forums, part of the General Programming Boards category; can some body tell , how to write function which calculates average of all the elements of the 2D array...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    3

    average of array elements?

    can some body tell , how to write function which
    calculates average of all the elements of the 2D array

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Sum the elements and divide by the number of elements. (Post your attempt -- and please use [code][/code] tags.)
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,171
    Walk through all the elements, summing them up. Then divide that total by the number of elements in the array.

    EDIT: Beaten to the punch *shakes fist at Dave*
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 08:25 PM
  2. What's wrong with my Average Array program?
    By special1zed in forum C Programming
    Replies: 12
    Last Post: 03-16-2009, 12:01 AM
  3. Left Shift elements of a 2D array
    By w2look in forum C Programming
    Replies: 8
    Last Post: 01-23-2009, 12:13 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. A simple question about selecting elements in an array
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 08-30-2001, 11:37 PM

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