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 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#include<stdio.h>
#include<math.h>
#define xplus (x= x >= n ? 0 : x+1)
#define yminus (y= x <= 0 ? n : y-1)
#define yplus (y= y >= n ? 0 : y+1)
int A[5][5],D,n;
int determinant_n(int n,int x,int y,int flag){
int i=0;
xplus;
if(n==1){
if(flag%2==0)
yplus;
else
yminus;
D=A[x][y];
printf("[%d]",D);
}
else{
yplus;
if(n%2==0)
for(D=0;i<n;i++,yplus){
D+=pow(-1,i)*A[x][y]*determinant_n(n-1,x,y,i);
printf("*%d\t\tSent(e) (%d,%d)\n",A[x][y],x,y);
}
else{
for(D=0;i<n;i++,yplus){
D+=A[x][y]*determinant_n(n-1,x,y,i);
printf("*%d\t\tSent(o) (%d,%d)\n",A[x][y],x,y);
}
}
}
return D;
}
int getdata(int n){
int x,y;
for(x=0;x<n;x++)
for(y=0;y<n;y++){
printf("A[%d][%d] = %d\n",x,y,n*x+y+1);
A[x][y]=n*x+y+1; //scanf("%d",&A[x][y]);
}
printf("\nthe Square Matrix is:\n");
for(x=0;x<n;x++){
for(y=0;y<n;y++)
printf("\t%d",A[x][y]);
printf("\n");
}
printf("__________________________________\n");
return 0;
}
int main(){
printf("Size of Square Matrix = ");
scanf("%d",&n);
getdata(n);
if(n>1)
D=determinant_n(n,-1,-1,0);
else return 0;
printf("Determinant of the Square Matrix = %d",D);
scanf("%d",&n);
return 0;
}
|