NxN no’malumli algebraik tenglamalar sistemasi beringan. Shu tenglamalar sistemasini yechish dasturini tuzing.
Yechish:
Dastur kodi:
namespace N*N nomalumli tenglamalar sistemasi
class GFG {
static int N = 4;
static void getCofactor(int[, ] mat, int[, ] temp,
int p, int q, int n)
{
int i = 0, j = 0;
for (int row = 0; row < n; row++)
{
for (int col = 0; col < n; col++)
{
if (row != p && col != q) {
temp[i, j++] = mat[row, col];
if (j == n - 1) {
j = 0;
i++;
}}}}}
static int determinantOfMatrix(int[, ] mat, int n)
{
int D = 0;
if (n == 1)
return mat[0, 0];
int[, ] temp = new int[N, N];
int sign = 1;
for (int f = 0; f < n; f++)
{
getCofactor(mat, temp, 0, f, n);
D += sign * mat[0, f]
* determinantOfMatrix(temp, n - 1);
sign = -sign;
}
return D;
}
static void display(int[, ] mat, int row, int col)
{
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
Console.Write(mat[i, j]);
Console.Write("\n");
}
}
public static void Main()
{
int[, ] mat = { { 1, 0, 2, -1 },
{ 3, 0, 0, 5 },
{ 2, 1, 4, -3 },
{ 1, 0, 5, 0 } };
Console.Write("Matritsaning determinanti: " + determinantOfMatrix(mat, N));
Console.ReadKey();
}
}
Ikkita matritsa berilgan. Ularning ko’paytmasini topish algoritmi va dasturini tuzing.
Yechish:
Dastur kodi:
namespace matritsalarni kopaytirish
{
class Program
{
public static void Main(string[] args)
{ int i = 0;
int j = 0;
int row = 2;
int col = 2;
int[,] Matrix1 = new int[row, col];
int[,] Matrix2 = new int[row, col];
int[,] Matrix3 = new int[row, col];
Console.Write("Birinchi matritsa elementini kiriting: ");
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
Matrix1[i, j] = int.Parse(Console.ReadLine());
}
}
Console.Write("Ikkinchi matritsa elementini kiriting: ");
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
Matrix2[i, j] = int.Parse(Console.ReadLine());
}
}
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
Matrix3[i, j] = 0;
for (int k = 0; k < 2; k++)
{
Matrix3[i, j] += Matrix1[i, k] * Matrix2[k, j];
}
}
}
Console.WriteLine'>WriteLine("\nMatrix1: ");
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
Console.Write(Matrix1[i, j] + "\t");
}
Console.WriteLine();
}
Console.WriteLine("\nMatrix2: ");
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
Console.Write(Matrix2[i, j] + "\t");
}
Console.WriteLine();
}
Console.WriteLine("\nMatrix3: ");
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
Console.Write(Matrix3[i, j] + "\t");
}
Console.WriteLine();
}
}
}
}
Natija:
Do'stlaringiz bilan baham: |