There is an array of NxN, you need to enter it in a trace format of an array of size N = 3

1 2 3 4 5 6 7 8 9 

Started with

 int[,] a = new int[101,101]; // исправил) string[] s = new string[101]; for (int i = 0; i < N; i++) s[i] = Console.ReadLine(); 

now you need ..

 s[i] Π² int a[i] 

as?

  • It is not clear why int [] a = new int [101] If you say a 3x3 two-dimensional array - Freezze
  • If you have a two-dimensional array of 3x3, then why do you need one-dimensional arrays of 101 elements in size? What is the logic in general? - DreamChild
  • oh error, where int [] a = new int [101]; I was mistaken, there int [,] a = new int [101,101]; on task n from 1 to 100, I solved the problem, and the system checking tasks (timus judge) requires the correct format of input data, that is, input by rows and columns - ixe

3 answers 3

Array size x size

  Console.Write("Π’Π²Π΅Π΄ΠΈΡ‚Π΅ Ρ€Π°Π·ΠΌΠ΅Ρ€ массива: "); int size = int.Parse(Console.ReadLine()); Console.WriteLine(); int[,] myMassive = new int[size, size]; for (int i = 0; i < myMassive.GetLength(0); i++) { string enterString = Console.ReadLine(); string[] massiveString = enterString.Split(new Char[] { ' ' }); for (int j = 0; j < massiveString.Length; j++) { myMassive[i, j] = int.Parse(massiveString[j]); } } 
  • what you brought above is: i.imgur.com/b2YoCoZ.png and in my case you need a line output before massive3x3.GetLnegth (1) massive3x3.GetLength (0) -fold -> i.imgur.com/zxyoVFu.png If I would need 1 option, I would not ask such stupid questions) - ixe
  • Line output? Or all the same line input? - Freezze
  • line-by-line input, in the case of just typing in a line (For example, enter two numbers separated by a space) I used the string [] s = Console.ReadLine (). Split (''); But here is an integer two-dimensional array and I have no idea how to be - ixe
  • That is, you get the line: 1 2 3 4 5 6, etc., where one line is the number entered through a space. This string must be parsed into an int array. I understand correctly? - Freezze
  • Yes, the user enters the number n (array size nxn) and then enters the array itself 4 1 3 6 10 2 5 9 13 4 8 12 15 7 11 14 16 - ixe

If you need input in one line, you can do so:

  Console.WriteLine("Input first dimension"); string rawFirstDimension = Console.ReadLine(); Console.WriteLine("Input second dimension"); string rawSecondDimension = Console.ReadLine(); int firstDimension; int secondDimension; // ΠΏΡ€ΠΎΠ²Π΅ΠΊΡ€ΠΊΠ° коррСктности Ρ€Π°Π·ΠΌΠ΅Ρ€ΠΎΠ² массива if (!int.TryParse(rawFirstDimension, out firstDimension) || !int.TryParse(rawSecondDimension, out secondDimension)) throw new Exception("Parsing failed"); var array = new int[firstDimension, secondDimension]; string rawStr = Console.ReadLine(); if (rawStr == null) // ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠ° массива Π½Π° пустоту throw new Exception("Array is empty"); var rawArray = rawStr.Split(' '); // ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠ° Π½Π° соотвСтствиС массива Ρ‚Ρ€Π΅Π±ΡƒΠ΅ΠΌΠΎΠΉ размСрности if(rawArray.Length != firstDimension * secondDimension) throw new Exception("Wrong array size"); for (int i = 0; i < firstDimension; i++) { for (int j = 0; j < secondDimension; j++) { int next; if (int.TryParse(rawArray[i * secondDimension + j], out next)) array[i, j] = next; else throw new Exception("Parsing failed");//Ссли ΠΎΡ‡Π΅Ρ€Π΅Π΄Π½ΠΎΠΉ элСмСнт Π½Π΅ число } } Console.WriteLine("Array is"); for (int i = 0; i < firstDimension; i++) { for (int j = 0; j < secondDimension; j++) Console.Write(array[i, j]); Console.WriteLine(); } 
  • Thank! I will note) - ixe

Input from the 2x2 array keyboard and output to the console

  int[,] numbers = new int[2,2]; for (int n = 0; n < 2; n++) { for (int m = 0; m < 2; m++) { Console.WriteLine("Enter number: "); numbers[n,m] = Convert.ToInt32(Console.ReadLine()); } Console.WriteLine(); } for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { Console.Write(numbers[i, j] + " "); } Console.WriteLine();