Dans R³
#include <stdio.h>
// Fonction pour calculer le déterminant d'une matrice 3x3
double determinant(double a1, double b1, double c1,
double a2, double b2, double c2,
double a3, double b3, double c3) {
return a1 * (b2 * c3 - b3 * c2)
- b1 * (a2 * c3 - a3 * c2)
+ c1 * (a2 * b3 - a3 * b2);
}
int main() {
double a1, b1, c1, d1;
double a2, b2, c2, d2;
double a3, b3, c3, d3;
// Lecture des coefficients du système
printf("Entrez les coefficients du système (a1 b1 c1 d1) : ");
scanf("%lf %lf %lf %lf", &a1, &b1, &c1, &d1);
printf("Entrez les coefficients du système (a2 b2 c2 d2) : ");
scanf("%lf %lf %lf %lf", &a2, &b2, &c2, &d2);
printf("Entrez les coefficients du système (a3 b3 c3 d3) : ");
scanf("%lf %lf %lf %lf", &a3, &b3, &c3, &d3);
// Calcul du déterminant principal
double D = determinant(a1, b1, c1, a2, b2, c2, a3, b3, c3);
// Calcul des déterminants partiels
double Dx = determinant(d1, b1, c1, d2, b2, c2, d3, b3, c3);
double Dy = determinant(a1, d1, c1, a2, d2, c2, a3, d3, c3);
double Dz = determinant(a1, b1, d1, a2, b2, d2, a3, b3, d3);
// Vérification des solutions
if (D != 0) {
double x = Dx / D;
double y = Dy / D;
double z = Dz / D;
printf("Solution unique : x = %.3lf, y = %.3lf, z = %.3lf\n", x, y, z);
} else {
if (Dx == 0 && Dy == 0 && Dz == 0) {
printf("Le système a une infinité de solutions.\n");
} else {
printf("Le système est impossible (pas de solution).\n");
}
}
return 0;
}