/*
* Created by SharpDevelop.
* User: Добромир
* Date: 21.12.2020 г.
* Time: 17:37
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Runtime.Remoting.Services;
namespace Двумерен_масив
{
class Program
{
static void Enter(ref sbyte[,] array)
{
for (sbyte row = 0; row < array.GetLength(0); row++)
for (sbyte col = 0; col < array.GetLength(1); col++)
{
do
Console.Write ("array[{0:D}, {1:D}] = ", row, col);
while (!sbyte.TryParse(Console.ReadLine(), out array[row, col]));
}
}
static sbyte NumberOfMatches(sbyte[,] array, sbyte X)
{
sbyte count = 0;
for (sbyte row = 0; row < array.GetLength(0); row++)
for (sbyte col = 0; col < array.GetLength(1); col++)
{
if (array[row, col] == X)
count++;
}
return count;
}
public static void Main(string[] args)
{
sbyte M, N;
do
Console.Write ("Брой редове M [2..7] = ");
while (!sbyte.TryParse(Console.ReadLine(), out M) || M < 2 || M > 7);
do
Console.Write ("Брой стълбове N [2..7] = ");
while (!sbyte.TryParse(Console.ReadLine(), out N) || N < 2 || N > 7);
sbyte[,] array = new sbyte[M, N];
Enter (ref array);
sbyte X;
do
Console.Write ("Търсено число X = ");
while (!sbyte.TryParse(Console.ReadLine(), out X));
sbyte count = NumberOfMatches (array, X);
Console.WriteLine ("Числото {0:D} се среща {1:D} пъти", X, count);
Console.WriteLine ("Масивът е:");
for (sbyte row = 0; row < array.GetLength(0); row++)
{
for (sbyte col = 0; col < array.GetLength(1); col++)
{
Console.Write ("{0:D} ", array[row, col]);
}
Console.WriteLine ();
}
Console.Write ("Press Escape key to End . . . ");
while (Console.ReadKey (true).Key != ConsoleKey.Escape);
}
}
}
Регистрирани потребители: Google [Bot]