How to calculate the determinant of a 2X2 matrix in Go

1 Answer

0 votes
package main

import "fmt"

func main() {
	arr := [2][2]int{{3, 8}, {4, 6}}

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

	determinant := (arr[0][0] * arr[1][1]) - (arr[0][1] * arr[1][0])

	fmt.Println(determinant)
}



/*
run:

-14

*/

 



answered Sep 5, 2024 by avibootz

Related questions

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