BasicKnowledgeCSharp/LessonsAndTasks/Lesson 32 - Заполнение двумерного масива, случайными числами/Program.cs
Dvurechensky bf6a7c2b4e 1.1
2025-05-12 02:48:54 +03:00

80 lines
2.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Author: Nikolay Dvurechensky
* Site: https://www.dvurechensky.pro/
* Gmail: dvurechenskysoft@gmail.com
* Last Updated: 12 мая 2025 02:47:11
* Version: 1.0.3
*/
using System;
/*
* Заполнение двумерного массива случайными числами
*
* Заполнение двумерного масива с клавиатуры
*/
class Program
{
static void Main()
{
int[,] myArray = new int[2, 2];
string[,] myArray1 = new string[2, 2];
Random rnd = new Random();
#region Random
for (int y = 0; y < myArray.GetLength(0); y++)
{
for (int x = 0; x < myArray.GetLength(1); x++)
{
myArray[y, x] = rnd.Next(0, 1000);
}
}
#endregion
#region Int
for (int y = 0; y < myArray.GetLength(0); y++)
{
for (int x = 0; x < myArray.GetLength(1); x++)
{
Console.Write($"Введите значение в элемент массива [myArray] под индексом [{0}][{1}]: ", y, x);
myArray[y, x] = int.Parse(Console.ReadLine());
Console.WriteLine();
}
Console.WriteLine();
}
for (int y = 0; y < myArray.GetLength(0); y++)
{
for (int x = 0; x < myArray.GetLength(1); x++)
{
Console.Write(myArray[y, x] + "\t");
}
Console.WriteLine();
}
#endregion
#region String
for (int y = 0; y < myArray1.GetLength(0); y++)
{
for (int x = 0; x < myArray1.GetLength(1); x++)
{
Console.Write($"Введите значение в элемент массива [myArray1] под индексом [{0}][{1}]: ", y, x);
myArray1[y, x] = Console.ReadLine();
Console.WriteLine();
}
Console.WriteLine();
}
for (int y = 0; y < myArray1.GetLength(0); y++)
{
for (int x = 0; x < myArray1.GetLength(1); x++)
{
Console.Write(myArray1[y, x] + "\t");
}
Console.WriteLine();
}
#endregion
Console.ReadKey();
}
}