How to calculate the determinant of a 2X2 matrix in C#

1 Answer

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            
            float[,] arr = new float[,] { { 3, 8 }, { 4, 6 } };

            /*
             *       a b
             * arr = 
             *       c d
             * 
             * determinant = a*d - b*c
             * 
             */

            float determinant = (arr[0,0] * arr[1,1]) - (arr[0,1] * arr[1,0]);

            Console.WriteLine(determinant);
        }
    }
}


/*
run:
    
-14

*/

 



answered Dec 3, 2016 by avibootz

Related questions

1 answer 111 views
1 answer 121 views
1 answer 113 views
1 answer 118 views
1 answer 132 views
1 answer 112 views
1 answer 131 views
...