commit db6b6ed9955dce8a2bfafb2b8eb1b115063d9c5c
parent c38249593fa9ecfdd658270755bfbf91446c52a4
Author: klewer-martin <martin.cachari@gmail.com>
Date: Wed, 31 Mar 2021 20:06:32 -0300
Update: ex45.c
Diffstat:
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/guia03/ex45.c b/guia03/ex45.c
@@ -24,7 +24,7 @@ int main (void)
/* Initialize the matrix with random numbers in range 0 - MATRIX_MAX */
for(size_t j = 0; j < N; j++) {
matrix[i][j] = ((double)rand()/(double)(RAND_MAX)) * 20;
- printf("%5.1f ", matrix[i][j]);
+ printf("%10f ", matrix[i][j]);
}
/* This to make it fancy too*/
@@ -38,7 +38,7 @@ int main (void)
determinant = matrix_det(N, matrix);
- printf("\nDeterminant = %2.1f.-\nTrace = %2.1f.-\n", determinant, trace);
+ printf("\nDeterminant = %10f.-\nTrace = %10f.-\n", determinant, trace);
return 0;
}
@@ -46,12 +46,10 @@ int main (void)
double matrix_det(size_t n, double matrix[][n])
{
double det;
- if(n == 2) {
- det = ((matrix[0][0] * matrix[1][1]) - (matrix[0][1] * matrix[1][0]));
- } else if (n == 3) {
- det = (matrix[0][0] * (matrix[1][1] * matrix[2][2] - matrix[1][2] * matrix[2][1]))
+ if(n == 2)
+ return ((matrix[0][0] * matrix[1][1]) - (matrix[0][1] * matrix[1][0]));
+ else if (n == 3)
+ return (matrix[0][0] * (matrix[1][1] * matrix[2][2] - matrix[1][2] * matrix[2][1]))
- (matrix[0][1] * (matrix[1][0] * matrix[2][2] - matrix[1][2] * matrix[2][0]))
- (matrix[0][2] * (matrix[1][0] * matrix[2][1] - matrix[1][1] * matrix[2][0]));
- }
- return det;
}