Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6771955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:29:35+00:00 2026-05-26T15:29:35+00:00

I’m new to this page and new to programming as well. Let me pose

  • 0

I’m new to this page and new to programming as well.
Let me pose my problem.
I have an array let’s say

1 2 3

4 5 6

7 8 9 

3 2 1

what I want to do is calculate for each row the difference between all elements.

{Math.Abs(1-2)=1

Math.Abs (2-3)=1

Math.Abs (1-3)=2}

for the first row. Next I want to find the average for each row(in first (1+1+2)/3) and finally keep the row with the smallest average value.

What is the most efficient way to do it??(I was thinking that perphaps LINQ could work but I don’t know how to properly use LINQ).
Any help would be appreciated.
Thank you all in advance!!!!

EDIT:
Thank you all for the answers…there are really usefull and helped me understand the way I should process my problem. I see that most all of you have recommended the use of List. So that raises another problem for me (remember little programming knowledge) how can I convert an int[,] array to List, is this is possible?? Should I convert int[,] to int[][] first and then to List ?
For one more time thank you for your answers and your time.

I created the following function for converting the 2d array to a List..but it seems that it’s not working properly..Any help would be truly appreciated..

 public static List<int[]> GetMyNumbers(int[,] result)
    {

        int[,] res = result;

        int length = res.GetUpperBound(0) + 1;
        int width = res.GetUpperBound(1) + 1;
        int[] rows = new int[width];
        List<int[]> numberArrays = new List<int[]>();

        for (int i = 0; i < result.Length / width; i++)
        {
            for (int k = 0; k < width; k++)
            {
                rows[k] = res[i, k];
                Console.Write(rows[k]);
            }
            Console.WriteLine();
            numberArrays.Add(rows);//this doesn't fill the list properly..It adds to all list items the last row of the 2d array

        }

        return numberArrays;


    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:29:35+00:00Added an answer on May 26, 2026 at 3:29 pm

    Here is what you are looking for basically. No I did not test the code to make sure that it is 100% correct, but should get you moving in the right direction at very least.

      // Look, a two dimensional version.
      int[][] numberArray = GetMyNumbers();
    
      // Placeholder for the lowest averge / corresponding index.
      double lowestAvg = double.MaxValue;
      int lowestIndex = -1;
    
      for (int rowIndex = 0; rowIndex < numberArray.Length; rowIndex++)
      {
    
        {
          int[] row = numberArray[rowIndex];
          int n = row.Length;
          int[] diffs = new int[(n * n) - n];
    
          // Get all of the differences.
          int count = 0;
          for (int i = 0; i < n; i++)
          {
            for (int j = i + 1; j < n; j++)
            {
              diffs[count] = Math.Abs(row[i] - row[j]);
              count++;
            }
          }
    
          // Average them..
          double sum = 0;
          for (int i = 0; i < diffs.Length; i++)
          {
            sum += diffs[i];
          }
          double avg = sum / diffs.Length;
    
          // Compare to the lowest value, making note of a new low.
          if (avg < lowestAvg)
          {
            lowestAvg = avg;
            lowestIndex = rowIndex;
          }
        }
    
      }
    
      // Now that we are here, we know which index has the lowest average of differences.
      // Do whatever you want with it.
      int[] TheAnswer = numberArray[lowestIndex];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.