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

  • SEARCH
  • Home
  • 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 3595146
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:48:48+00:00 2026-05-18T19:48:48+00:00

in the code below i want to implement the floyd algorithm,the user enter some

  • 0

in the code below i want to implement the floyd algorithm,the user enter some numbers in textbox and output should be the shortest distances that can go from node i to node j.but when i enter for example 4 number it gives run time error:out of range on the line i commented below,and i debugged it,i understood that k,i just take 1 value and doesnt take another values less than n+1 but j can take all of the values less than n+1,what can i solve this problem?thanks so much

edited:
thanks for your answers i corrected that

 private void button10_Click(object sender, EventArgs e)
 {

    string ab = textBox11.Text;

    int matrixDimention = Convert.ToInt32(ab);

    int[,] intValues = new int[matrixDimention, matrixDimention];

    string[] splitValues = textBox9.Text.Split(',');

    for (int i = 0; i < splitValues.Length; i++)

        intValues[i / (matrixDimention), i % (matrixDimention)] = Convert.ToInt32(splitValues[i]);
    string displayString = "";

    for (int inner = 0; inner < intValues.GetLength(0); inner++)
    {
        for (int outer = 0; outer < intValues.GetLength(0); outer++)

            displayString += String.Format("{0}\t", intValues[inner, outer]);

        displayString += Environment.NewLine;
    }
   int n=matrixDimension

    MessageBox.Show("matrix"+strn+ "in" + strn + "is\n\n\n" +displayString);

////before this line i wrote the codes to get the numbers that user enter in textbox and put it in an 2d array
    for (int k = 0; k < n; k++)/// k just take 1 in debugging!!!

        for (int i = 0; i < n; i++)///i just take 1 in debugging!!!

            for (int j = 0; j < n; j++)///j took the values true

       /*i took that error on this line  */ if (intValues[i, j] > intValues[i, k] + intValues[k, j])
                {
                    intValues[i, j] = intValues[i, k] + intValues[k, j];

                    string str_intvalues = intValues[i, j].ToString();

                    MessageBox.Show("Shortest Path from i to j is: " + str_intvalues);

                }
                else
                {
                    string str_intvalues = intValues[i, j].ToString();
                    MessageBox.Show("Shortest Path from i to j is: " + str_intvalues);

                }
}
  • 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-18T19:48:49+00:00Added an answer on May 18, 2026 at 7:48 pm

    Most programming languages, including C#, start counting array cells from position 0.

    This means that if you have an array of size N, you get indexes from 0 to N-1.

    So all your loops should look like this:

    for (int j = 0; j < n; j++)
    

    AND, as I looked at the code again, I realized that you intValues is a 2D matrix with the size matrixDimention to each side. BUT n is of the size (int)Math.Pow(matrixDimention, 2) .

    So if you try to access intValues when k passes matrixDimention you’ll get out of bounds.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below is my code for setting up a listview. I want to implement a
I want to implement VideoRecording function. I have the below code,but it throws me
See code below: I want Page 1 to alert #testing... This works in C
I have the code below and I want to loop this every 5 seconds.
As a PHP developer, I always use the code below whenever I want to
The code below does not work but meant to illustrate what I want to
I want to know if the code below removes all input type='text' values back
Using the code below, I want to keep the same menu div opened in
In the code below, I don't want to use instanceof to know the type
I have the following code below which works, but I want to insert values

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.