### program crashes.. anything wrong??

I made a program on Cramer's Rule but after taking input it just crashes ... Please Help if u can find out whats wrong with my code...
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061`` ``````#include #include 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; }``````

You've forgotten 'int' before main( line 5 )
It did not help!!!
i think if there is any problem with using a function into another function? (line 59)
If det(A) is zero you'll be dividing by zero.

What inputs are you using to make it crash?
I couldn't reproduce it. ¿where does the crash happen?

Your algorithm is incorrect as you are overwriting the matrix in the `swapper', then Z will always be 0.

Also `printf("\n\nThe Value of X = %0.2f",((double)X)/O);` integer division returns an integer.
I think there is problem with your algorithm
Suppose you are entering

a1 b1 c1 d1
a2 b2 c2 d2
a3 b3 c3 d3

In first step when you replace

a1
a2
a3

with
d1
d2
d3

and in second step when you are replacing { b2 b2 b3} with {d1 d2 d3}
a1 a2 a3 is still replaced with d1 d2 d3
So et the end your matrix is

d1 d1 d1 d1
d2 d2 d2 d2
d3 d3 d3 d3
Can you make the corrections for me i will very grateful
Thanks sir that was very helpful ... i fixed that problem you just pointed out by making a backup of values and then replacing it before returning value ... Thanks again Sir TTT
Topic archived. No new replies allowed.