Answer the question
In order to leave comments, you need to log in
C# - How to fix the error - Index was outside the bounds of the array?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Введите порядок матрицы");
int N = Int32.Parse(Console.ReadLine());
int M = Int32.Parse(Console.ReadLine());
Console.WriteLine();
int[,] a = new int[N, M];
int[] b = new int[N];
int max;
Random rnd = new Random();
max = 0;
for (int i = 0; i < N; i++)
{
for (int j = 0; j < M; j++)
{
a[i, j] = rnd.Next(0, 10);
Console.Write(a[i, j] + "\t");
}
Console.WriteLine();
}
Console.WriteLine();
for (int i = 0; i < N; i++)
{
for (int j = 0; i < M; j++)
{
if (a[i, j] > max)
{
max = a[i, j];
}
}
b[i] = max;
Console.Write(b[i] + "\t");
}
Console.WriteLine();
}
}
Answer the question
In order to leave comments, you need to log in
I advise you to use x, y, .... for multidimensional arrays and not to use similar letters.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question