Here's the program that will form your square matrix to upper/lower triangular(as u like);and then will give you the determinant of the following matrix,There you go(again the same issue,Long code...) :
Code:
Program Lower_And_Upper_Triangular(input,output);
(*Programmer S-T,Number:8811021 Programmer:Alireza Date:4,12,2009
This program will input a matrix and will output lower/Upper triangular
form of it*)
Uses CRT;
Type
Mat=Array[1..30,1..30] Of real;
Var
I,J,L,M,Rows,Form:Integer;
Matrix:Mat;
K,Multi:real;
Procedure ReadingMatrix(Var Matrix:Mat;Rows:integer);
Var
ii,jj:integer;
Element:real;
Begin
Writeln(' Please enter the elements of your ',Rows,' X ',Rows,' Matrix');
For ii:=1 To Rows Do
Begin
For jj:=1 To Rows Do
Begin
Read(Element);
Matrix[ii,jj]:=Element;
End;
End;
End;
Procedure PrintingMatrix(Matrix:Mat;Rows:integer);
Var
ii,jj:integer;
Element:real;
Begin
Writeln;
Writeln(' Here are your matrix ');
Textcolor(Green);
For ii:=1 To Rows Do
Begin
For jj:=1 To Rows Do
Begin
Write(Matrix[ii,jj]:5:2);
End;
Writeln;
End;
End;
Begin
CLRSCR;
TextColor(yellow);
Writeln('Please Enter number of your matrix`s Rows');
Readln(Rows);
ReadingMatrix(Matrix,Rows);
Writeln('Now If you want your matrix in Lower triangular Form Press 1');
Writeln('Now If you want your matrix in Upper triangular Form Press 2');
Read(Form);
Case Form OF
1 : Begin
For L:=Rows DownTo 2 Do
Begin
For I:=1 tO L-1 Do
Begin
If Matrix[I,L]=0 Then
Begin
End
Else
If Matrix[L,L]=0 Then
Begin
For M:=Rows DownTo 1 Do
Begin
Matrix[L,M]:=Matrix[i,M]+Matrix[L,M];
End;
End;
K:=0;
K:=(-1)*Matrix[I,L]/Matrix[L,L];
For J:=Rows DownTo 1 Do
Begin
Matrix[I,J]:=K*Matrix[L,J]+Matrix[I,J];
End;
End;
End;
Multi:=1;
For I:=1 To Rows Do
Begin
Multi:=Multi*Matrix[i,i];
End;
PrintingMatrix(Matrix,Rows);
Writeln;
Write('Your matrix determinant is -> ');
Textcolor(Red);
Write(' ',Multi:7:3);
End;
2 : Begin
For L:=1 To Rows-1 Do
Begin
For I:=Rows DownTo L+1 Do
Begin
If Matrix[I,L]=0 Then
Begin
End
Else
If Matrix[L,L]=0 Then
Begin
For M:=Rows DownTo 1 Do
Begin
Matrix[L,M]:=Matrix[i,M]+Matrix[L,M];
End;
End;
K:=0;
K:=(-1)*Matrix[I,L]/Matrix[L,L];
For J:=Rows DownTo 1 Do
Begin
Matrix[I,J]:=K*Matrix[L,J]+Matrix[I,J];
End;
End;
End;
Multi:=1;
For I:=1 To Rows Do
Begin
Multi:=Multi*Matrix[i,i];
End;
PrintingMatrix(Matrix,Rows);
Writeln;
Write('Your matrix determinant is -> ');
Textcolor(Red);
Write(' ',Multi:7:3);
End;
End;
Textcolor(White);
Delay(1500);
Writeln;
Writeln;
Writeln('CODED BY ALIREZA_M');
Repeat
Until Keypressed;
End.