programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Paul Clapham
• Ron McLeod
• paul wheaton
• Devaka Cooray
Sheriffs:
• Jeanne Boyarsky
• Tim Cooke
• Liutauras Vilda
Saloon Keepers:
• Tim Moores
• Tim Holloway
• Stephan van Hulst
• Carey Brown
• Piet Souris
Bartenders:
• salvin francis
• Mikalai Zaikin
• Himai Minh

# How to find average value of a row in a 2D array?

Greenhorn
Posts: 1
• Number of slices to send:
Optional 'thank-you' note:
I want to make a program to store data of rainfalls for 3 years. Initialized an array of double rainfalls[3][12]...Made one function to find average rainfall values of the 2D array...Found the average rainfall of the total of 3 years but how do i find the average of per year? Like how do i find the average of 1st year, 2nd year and 3rd year individually??Here's the code:

Marshal
Posts: 72612
317
• Number of slices to send:
Optional 'thank-you' note:
Welcome to the Ranch

Thank you for using the code button, but you didn't quite get it right. Please see the link on the left. If I remember, I'll correct that for you and it will look much better
Your question would fit better in another forum, so I shall move you there.

You calculate the arithmetical mean, which is probably the average you want, by adding all the numbers and dividing by how many numbers there are (12 or 36). You seem to be doing that already; please tell us whether your program doesn't work.

Why are you asking for keyboard input when you already have those figures in the array?

Campbell Ritchie
Marshal
Posts: 72612
317
• Number of slices to send:
Optional 'thank-you' note:
You can iterate the rows and calculate the averages for each row: simply do the arithmetic inside the outer loop.

 What does a metric clock look like? I bet it is nothing like this tiny ad: ScroogeXHTML - a fast and small RTF to HTML5 and XHTML converter library https://coderanch.com/t/742149/ScroogeXHTML-RTF-HTML-XHTML-converter