Thread: average of array elements?

  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,005
    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,218
    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, 07:25 PM
  2. What's wrong with my Average Array program?
    By special1zed in forum C Programming
    Replies: 12
    Last Post: 03-15-2009, 11:01 PM
  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, 09: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, 10:37 PM