Пример #1
0
        public MatricePatratica(MatricePatratica A)
        {
            int i;

            set_size(A.NrLin, A.NrCol);
            for (i = 0; i < A.NrLin; ++i)
            {
                mat[i] = A.mat[i];
            }
        }
Пример #2
0
        public int Determinant()
        {
            int det;

            if (NrLin == 1)
            {
                return(mat[0][0]);
            }
            int i, j;

            det = 0;
            i   = 0;
            for (j = 0; j < NrCol; ++j)
            {
                ///construiesc matricea care ramane
                MatricePatratica aux;
                aux = new MatricePatratica();

                aux.set_size(NrLin - 1, NrLin - 1);

                for (int i1 = 1; i1 < NrLin; ++i1)
                {
                    for (int j1 = 0; j1 < NrLin; ++j1)
                    {
                        if (j1 < j)
                        {
                            aux[i1 - 1][j1] = mat[i1][j1];
                        }
                        if (j1 > j)
                        {
                            aux[i1 - 1][j1 - 1] = mat[i1][j1];
                        }
                    }
                }
                int pow;
                if ((i + j) % 2 == 0)
                {
                    pow = 1;
                }
                else
                {
                    pow = -1;
                }
                det += pow * mat[i][j] * aux.Determinant();
            }
            return(det);
        }
Пример #3
0
        static void Main(string[] args)
        {
            int i, j, n;

            Console.Write("Numarul de linii (si coloane) al matriei patratice: ");
            n = int.Parse(Console.ReadLine());
            MatricePatratica A = new MatricePatratica(n);

            for (i = 0; i < n; ++i)
            {
                for (j = 0; j < n; ++j)
                {
                    A[i][j] = int.Parse(Console.ReadLine());
                }
            }

            Console.WriteLine("Determinantul este: " + A.Determinant());
            Console.ReadLine();
        }