#include double det(double arr[][3]) { double ans; ans=(((arr[0][0]*arr[1][1]*arr[2][2])+ (arr[0][1]*arr[1][2]*arr[2][0])+ (arr[0][2]*arr[1][0]*arr[2][1]))- ((arr[0][2]*arr[1][1]*arr[2][0])+ (arr[0][0]*arr[1][2]*arr[2][1])+ (arr[0][1]*arr[1][0]*arr[2][2]))); return ans; } void sol(double x,double y,double z) { printf("Solution:\n"); printf("x = %lf\n",x); printf("y = %lf\n",y); printf("z = %lf\n",z); } void accept(double arr [][3],double arr1[3]) { int i,j; printf("\n\nAccepted equations:\n"); for (i=0;i<3;i++) { for (j=0;j<3;j++) { switch (j) { case 0: printf("%.1lfx",arr[i][j]); break; case 1: if (arr[i][j]>0) printf("+%.1lfy",arr[i][j]); else if (arr[i][j]<0) printf("%.1lfy",arr[i][j]); break; case 2: if (arr[i][j]>0) printf("+%.1lfz",arr[i][j]); else if (arr[i][j]<0) printf("%.1lfz",arr[i][j]); break; } } printf("=%.1lf\n",arr1[i]); } } /*The input function and my problem with the scanf by running we can see that he enter the function becuase he print the message and after that he skips and ignore the scanf*/ void input(double A[][3],double X[3]) { printf("\nEnter coefficients and constants:\n"); scanf("{{%lf,%lf,%lf},{%lf,%lf,%lf},{%lf,%lf,%lf}}={%lf,%lf,%lf}", &A[0][0], &A[0][1], &A[0][2], &A[1][0], &A[1][1], &A[1][2], &A[2][0], &A[2][1], &A[2][2], &X[0], &X[1], &X[2]); } void main() { double coef[3][3]={0}; double temp[3][3]={0}; double con[3]={0}; double main_det=0,solX=0,solY=0,solZ=0; int i=0,j=0,choice=0; printf("Main Menu\n"); printf("(1)Solve 3x3 linear equations system\n"); printf("(2)Quit\n"); printf("Enter your choice:"); scanf("%d", &choice); if (choice==1) { input(coef,con); /*input function*/ accept(coef,con); main_det=det(coef); if (main_det==0) { printf("The metrix doesn't have one solution"); } else { for (i=0;i<3;i++) for (j=0;j<3;j++) temp[i][j]=coef[i][j]; for (i=0;i<3;i++) temp[i][0]=con[i]; solX=det(temp)/main_det; for (i=0;i<3;i++) { temp[i][1]=con[i]; temp[i][0]=coef[i][0]; } solY=det(temp)/main_det; for (i=0;i<3;i++) { temp[i][2]=con[i]; temp[i][1]=coef[i][1]; } solZ=det(temp)/main_det; sol(solX,solY,solZ); } } else printf("bye bye...\n"); }