# C++ determinant of diagonal matrix

• Comp Sci

## Homework Statement

well, my assignment was to make a gauss elimination, so now i need to compute the determinant of an n by n diagonal matrix

variable rows = number of equations
variable i = random integer
matrix A
dummy matrix A2

## Homework Equations

det[A] = A*A*A*........*A[n][n]

## The Attempt at a Solution

i made the code for pivoting and forward elimination, but i spent 2 hours or so and i couldn't figure out how to make a code for this using for loop

for (i=0;i<rows;i++){
A2 = A*A[i+1][i+1]
}
(this will only ever give me a product of 2 numbers in the diagonal though)

i thought it was going to be easy but i need to find a formula so it stores the products of all the elements in the diagonal of the matrix

PS; there is only so much attempts i can show, since i have no clue whatsoever to go about this.

@borek

thanks a lot i got the answer u helped a lot, i also realized my back elimination formula was wrong and your method helped me alot once again

Last edited: