CODUL

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

using

using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading.Tasks;

namespace ConsoleApplication4
{
public class Program
{
static int determinant = 0;
static int produs = 1;
static int[] st = new int[150];
static int n;
static int[,] matrice= new int[150,150];
static int semnulinversiunii(int[] p)
{
int semn=-1;
int suma = 0;
for (int i = 1; i <= n; i++)
{
for (int j = i+1; j<= n; j++)
{
if (p[i] > p[j])
{
suma += 1;
}
}
}
return (int)Math.Pow(semn,suma);
}
static void initializator()
{
Console.WriteLine("Va rog sa introduceti dimensiunea matricei ");
Console.WriteLine("n=");
n = Convert.ToInt32(Console.ReadLine());
for (int i = 1; i <= n; i++)
{
st[i] = 0;
}

for (int i = 1; i <= n; i++)


{
for (int j = 1; j <= n; j++)
{
Console.Write("Elementul de pe pozitia:"+i+","+j+" este : ")
;
matrice[i, j] = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();
}
}
}
static int valid(int p)
{
int i, ok;
ok = 1;
for (i = 1; i <= p - 1; i++)
{
if (st[p] == st[i])
{
ok = 0;
}
}
return ok;
}
static void tipar(int p)
{
int i;
for (i = 1; i <= p; i++)
{
Console.Write(st[i]);

}
Console.Write(" Signatura este: ");Console.Write(semnulinversiunii(s
t));
Console.Write(" \n");
}
static void bktr(int p)
{
int pval;
for (pval = 1; pval <= n; pval++)

{
st[p] = pval;
if (valid(p) !=0)
if (p == n)
{
//tipar(p);
for (int a=1;a<=n;a++)
{
produs = produs*matrice[a, st[a]];
}
determinant = determinant + semnulinversiunii(st) * produs;
produs = 1;
}
else
bktr(p + 1);
}
}
static void Main(string[] args)
{
initializator();
bktr(1);
Console.WriteLine(determinant);
}
}
}

You might also like