?
Solved

Max, Min and Average of a selection of Cells in Array 2D on C#?

Posted on 2011-10-19
6
Medium Priority
?
370 Views
Last Modified: 2012-05-12
On C#.
If int myArray [310,220];
How to know the Max, Min and Average of a selection of cells?
Example:
int myArrayMax = FROM HERE myArray[55,10] TO HERE myArray[250,200];
int myArrayMin  = FROM HERE myArray[55,10] TO HERE myArray[250,200];
double myArrayAverage = FROM HERE myArray[55,10] TO HERE myArray[250,200];

Thank you,
ocaccy
0
Comment
Question by:ocaccy
  • 3
  • 2
6 Comments
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 36997976
Using linq you can find it easily

nt myArrayMax = myArray.Max()
nt myArrayMax = myArray.Min()
nt myArrayMax = myArray.Avg()



http://www.java2s.com/Code/CSharp/LINQ/Maxonintarray.htm
0
 

Author Comment

by:ocaccy
ID: 36998874
Thank you. Very good information.

However, I still need to know how to make the Average, Min, Max and Sum on a 2D array, and the same thing in a selection of cells, not the entire array.

Thank you very much,
ocaccy

int myArrayMax = FROM HERE myArray[55,10] TO HERE myArray[250,200];
int myArrayMin  = FROM HERE myArray[55,10] TO HERE myArray[250,200];
double myArrayAverage = FROM HERE myArray[55,10] TO HERE myArray[250,200];

Open in new window

0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 37006810
This question was answered here http:Q_27408102.html#37004473
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:ocaccy
ID: 37021330
TommySzalapski, wrote this:

int max(int[,] array, int first_col, int last_col, int first_row, int last_row)

However, I need for loop for this too.
In C#.

for loop running like this:

myArray2[0,0] = maximun from here - myArray1[1,0] to here myArray1[3,0];
myArray2[1,0] = average from here - myArray1[4,0] to here myArray1[6,0];

i need a for loop, because it will be so in all 60 columns in myArray1 with myArray2.

Regards,
ocaccy
Array-For-loop.png
0
 
LVL 37

Accepted Solution

by:
TommySzalapski earned 2000 total points
ID: 37025003
So you need something like this (using the functions we built in the other question).
for(int i = 0; i < 60; ++i)
{
  myArray2[0][i] = max(myArray1(1, 3, i, i);
  myArray2[1][i] = average(myArray1(4, 6, i, i);
}

Open in new window

0
 

Author Closing Comment

by:ocaccy
ID: 37028308
Thank you Tommy.

You have helped me a lot in the arrays.

Best Regards,
ocaccy
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you don't know how to downgrade, my instructions below should be helpful.
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question