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 135 views
1 answer 104 views
1 answer 110 views
1 answer 106 views
1 answer 119 views
1 answer 106 views
1 answer 118 views
...