Ответ:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define N 10
void getCofactor(double matrix[N][N], double temp[N][N], int p, int q, int n) {
int i = 0, j = 0;
for (int row = 0; row < n; row++) {
for (int col = 0; col < n; col++) {
if (row != p && col != q) {
temp[i][j++] = matrix[row][col];
if (j == n - 1) {
j = 0;
i++;
}
double determinant(double matrix[N][N], int n) {
double det = 0;
if (n == 1) {
return matrix[0][0];
} else if (n == 2) {
return matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0];
double temp[N][N];
int sign = 1;
for (int f = 0; f < n; f++) {
getCofactor(matrix, temp, 0, f, n);
det += sign * matrix[0][f] * determinant(temp, n - 1);
sign = -sign;
return det;
int main() {
int n;
printf("Enter the size of the square matrix (max 10): ");
scanf("%d", &n);
double matrix[N][N];
printf("Enter the elements of the square matrix:\n");
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
scanf("%lf", &matrix[i][j]);
double det = determinant(matrix, n);
printf("Determinant of the matrix is: %lf\n", det);
return 0;
Объяснение:
Удачи)
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
Ответ:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define N 10
void getCofactor(double matrix[N][N], double temp[N][N], int p, int q, int n) {
int i = 0, j = 0;
for (int row = 0; row < n; row++) {
for (int col = 0; col < n; col++) {
if (row != p && col != q) {
temp[i][j++] = matrix[row][col];
if (j == n - 1) {
j = 0;
i++;
}
}
}
}
}
double determinant(double matrix[N][N], int n) {
double det = 0;
if (n == 1) {
return matrix[0][0];
} else if (n == 2) {
return matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0];
}
double temp[N][N];
int sign = 1;
for (int f = 0; f < n; f++) {
getCofactor(matrix, temp, 0, f, n);
det += sign * matrix[0][f] * determinant(temp, n - 1);
sign = -sign;
}
return det;
}
int main() {
int n;
printf("Enter the size of the square matrix (max 10): ");
scanf("%d", &n);
double matrix[N][N];
printf("Enter the elements of the square matrix:\n");
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
scanf("%lf", &matrix[i][j]);
}
}
double det = determinant(matrix, n);
printf("Determinant of the matrix is: %lf\n", det);
return 0;
}
Объяснение:
Удачи)