1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#include<stdio.h>
#include<conio.h>
int det(int A[3][4]);
int swapper(int A[3][4],int col);
main()
{
int A[3][4],i,j;
printf("Enter Coefficients of all equations:\nfor example:\n\tfor\t 25x + 8y + 9z = 24\nYou will enter 25 8 9 24:\n\n\n");
for (i=0;i<3;i++)
{
printf("Enter the Coefficients of Equation # %d:",i+1);
for(j=0;j<4;j++)
{
scanf("%d",&A[i][j]);
}
}
int O = det(A);
int X = swapper(A,0);
int Y = swapper(A,1);
int Z = swapper(A,2);
printf("\n\nThe Value of X = %0.2f",X/O);
printf("\nThe Value of Y = %0.2f",Y/O);
printf("\nThe Value of Z = %0.2f",Z/O);
getch();
}
int det(int A[3][4])
{
int i,j,x,y,L[4],u=0,X[3],g=0;
for(i=0;i<3;i++)
{
j=0;
for(x=0;x<3;x++)
{
for(y=0;y<3;y++)
{
if(x!=j&&y!=i)
{
L[u]=A[x][y];
u++;
}
}
}
X[g]=A[j][i]*((L[0]*L[3])-(L[1]*L[2]));
g++;
u=0;
}
return (X[0]-X[1]+X[2]);
}
int swapper(int A[3][4],int col)
{
int x;
for(x=0;x<3;x++)
{
A[x][col]=A[x][3];
}
int c = det(A);
return c;
}
|