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 76 77 78 79 80 81
|
#include<stdio.h>
float A[5][5],E[5][5],D=1,ms=1;
int n;
int getdata(int n){
int x,y;
for(x=0;x<n;x++){
for(y=0;y<n;y++){
printf("A[%d][%d] = ",x,y);//n*x+y+1);
//A[x][y]=(float)n*x+y+1;
scanf("%f",&A[x][y]);
}
}
return 0;
}
int showdata(int n){
int x,y;
for(x=0;x<n;x++){
printf("\n");
for(y=0;y<n;y++){
printf("\t%3.1f",A[x][y]);
}
}
printf("\n");
return 0;
}
int row_echelon(int n){
int x,y,j;
float m,s;
for(x=y=0;y<n;y++,x=y){
if((A[x][y]!=1)&&(A[x][y]!=0)){
m=1/A[x][y];
ms*=m;
for(j=y;j<n;j++){
A[x][j]*=m;
}
}
for(x=y+1;x<n;x++){
if(A[x][y]!=0){
s=A[x][y];
for(j=y;j<n;j++){
A[x][j]-=A[y][j]*s;
}
}
}
}
return 0;
}
int determinant(int n){
for(;n>0;n--){
D*=A[n-1][n-1];
}
D/=ms;
return 0;
}
int main(){
printf("Enter the size of the matrix : ");
scanf("%d",&n);
getdata(n);
showdata(n);
printf("\nThe row-echelon form of the matrix : \n");
row_echelon(n);
showdata(n);
determinant(n);
printf("\nThe Determinant of the matrix : %3.1f\n",D);
system("pause");
return 0;
}
|