Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace myloyorrr
- {
- internal class Program
- {
- static void In(int[,] a)
- {
- for (int i = 0; i < a.GetLength(0); i++)
- {
- string[]s = Console.ReadLine().Split();
- for (int j = 0; j < a.GetLength(1); j++)
- {
- a[i, j] = int.Parse(s[j]);
- }
- }
- }
- static void Out(int[,] a)
- {
- for (int i = 0; i < a.GetLength(0); i++)
- {
- for (int j = 0; j < a.GetLength(1); j++)
- {
- Console.Write(a[i, j] + " ");
- }
- Console.WriteLine();
- }
- }
- static int det(int[,] a)
- {
- int ans = 0;
- int k = 1;
- if(a.GetLength(0) == 1)
- {
- ans = a[0, 0];
- }
- else if(a.GetLength(0) == 2)
- {
- ans = a[0, 0] * a[1, 1] - a[0, 1] * a[1, 0];
- }
- else if(a.GetLength(0) >= 3)
- {
- for(int j = 0; j < a.GetLength(1); j++)
- {
- int[,] b;
- b = new int[a.GetLength(0)-1, a.GetLength(0)-1];
- for (int x = 1; x < a.GetLength(0); x++)
- {
- for (int y = 0; y < a.GetLength(1); y++)
- {
- if(y < j)
- {
- b[x - 1, y] = a[x, y];
- }
- else if(y > j)
- {
- b[x - 1, y-1] = a[x, y];
- }
- }
- }
- ans += k * a[0, j] * det(b);
- k *= (-1);
- }
- }
- return ans;
- }
- static void Main()
- {
- int[,] a;
- int n = int.Parse(Console.ReadLine());
- a = new int[n, n];
- In(a);
- Console.WriteLine(det(a));
- //Out(a);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement