đây a
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bai2
{
class Bai2
{
static public int[,] iMaTran = new int[100, 100];
static public int n, m;
public int k;
void nhapmatran(int[,] iMaTran, int m, int n)
{
Console.Write("Nhap so dong:");
m = int.Parse(Console.ReadLine());
Console.Write("Nhap so cot:");
n = int.Parse(Console.ReadLine());
Console.WriteLine("Nhap ma tran:");
for (int i = 1; i <= m; i++)
{
for (int j = 1; j <= n; j++)
{
Console.Write("Nhap phan tu dong {0} ,cot {1} :", i, j);
iMaTran[i, j] = int.Parse(Console.ReadLine());
}
Console.WriteLine();
}
Console.WriteLine("Ma Tran vua nhap:");
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
Console.Write(+iMaTran[i, j] + " ");
Console.WriteLine();
}
}
public void XuatMaTran( int[,] iMaTran, int n, int m)
{
for (int i = 1; i <=n; i++)
{
for (int j = 1; j <= m; j++)
Console.Write(+iMaTran[i, j] + " ");
Console.WriteLine();
}
}
bool timkiem(int[,] iMaTran, int m, int n)
{
Console.Write("Nhap phan tu can tim kiem trong mang: ");
k = int.Parse(Console.ReadLine());
for (int i = 1; i <= m; i++)
{
for (int j = 1; j <= n; j++)
{
if (iMaTran[i, j] == k)
return true;
}
}
return false;
}
static void Main(string[] args)
{
int[,] iMaTran;
iMaTran = new int[100, 100];
Bai2 test = new Bai2();
test.nhapmatran(iMaTran, m, n);
if (test.timkiem(iMaTran, m, n) == true)
Console.Write("Co phan tu trong mang ");
else
Console.Write("ko co phan tu trong mang ");
Console.ReadLine();
}
}
}