restart:# GAUSSIAN ELIMINATION WITH BACKWARD SUBSTITUTION ALGOTITHM 6.1## To solve the n by n linear system## E1: A[1,1] X[1] + A[1,2] X[2] +...+ A[1,n] X[n] = A[1,n+1]# E2: A[2,1] X[1] + A[2,2] X[2] +...+ A[2,n] X[n] = A[2,n+1]# :# .# EN: A[n,1] X[1] + A[n,2] X[2] +...+ A[n,n] X[n] = A[n,n+1]## INPUT: number of unknowns and equations n: augmented# matrix A = (A(I,J)) where 1<=I<=n and 1<=J<=n+1.## OUTPUT: solution x(1), x(2),...,x(n) or a message that the# linear system has no unique solution.print(`This is Gaussian Elimination to solve a linear system.`):print(`Choice of input method`):print(`1. input from keyboard - not recommended for large systems`):print(`2. input from a text file`):print(`Please enter 1 or 2.`):FLAG := scanf(`%d`)[1]: print(`Your input is`): print(FLAG):if FLAG = 2 thenprint(`The array will be input from a text file in the order`):print(`A(1,1), A(1,2), ..., A(1,N+1), A(2,1), A(2,2), ..., A(2,N+1)`):print(`..., A(N,1), A(N,2), ..., A(N,N+1)\134n`):print(`Place as many entries as desired on each line, but separate `):print(`entries with`):print(`at least one blank.`):print(`Has the input file been created? - enter 1 for yes or 2 for no.`):AA := scanf(`%d`)[1]: print(`Your response is`): print(AA):if AA = 1 thenprint(`Input the file name in the form - drive:\134\134name.ext`):print(`for example: A:\134\134DATA.DTA`):NAME := scanf(`%s`)[1]: print(`The file name is`): print(NAME):INP := fopen(NAME,READ,TEXT):OK := FALSE:while OK = FALSE doprint(`Input the number of equations - an integer.`):N := scanf(`%d`)[1]: print(`N is`): print(N):if N > 0 thenfor I1 from 1 to N dofor J from 1 to N+1 doA[I1-1,J-1] := fscanf(INP, `%f`)[1]:od:od:OK := TRUE:fclose(INP):else print(`The number must be a positive integer.\134n`):fi:od:else print(`The program will end so the input file can be created.\134n`):fi:elseOK := FALSE:while OK = FALSE doprint(`Input the number of equations - an integer.`):N := scanf(`%d`)[1]: print(`N= `): print(N):if N > 0 thenfor I1 from 1 to N dofor J from 1 to N+1 doprint(`input entry in position `,I1,J): A[I1-1,J-1] := scanf(`%f`)[1]:print(`Data is `):print(A[I1-1,J-1]):od:od:OK := TRUE:else print(`The number must be a positive integer.\134n`):fi:od:fi:if OK = TRUE thenOUP := default:fprintf(OUP, `The original system - output by rows:\134n`):for I1 from 1 to N dofor J from 1 to N+1 dofprintf(OUP, ` %11.8f`, A[I1-1,J-1]):od:fprintf(OUP, `\134n`):od:# Step 1NN := N-1:M := N+1:ICHG := 0:I1 := 1:while OK = TRUE and I1 <= NN do# Step 2# Use IP in place of PIP := I1:while abs(A[IP-1,I1-1]) <= 1.0e-20 and IP <= N doIP := IP+1:od:if IP = M thenOK := FALSE:else# Step 3if IP <> I1 thenfor JJ from 1 to M doC := A[I1-1,JJ-1]:A[I1-1,JJ-1] := A[IP-1,JJ-1]:A[IP-1,JJ-1] := C:od:ICHG := ICHG+1:fi:# Step 4JJ := I1+1:for J from JJ to N do# Step 5# XM is used in place of m(J,I)XM := A[J-1,I1-1]/A[I1-1,I1-1]:# Step 6for K from JJ to M doA[J-1,K-1] := A[J-1,K-1] - XM * A[I1-1,K-1]:od:# Multiplier XM could be saved in A[J,I]A[J-1,I1-1] := 0:od:fi:I1 := I1+1:od:if OK = TRUEthen# Step 7if abs(A[N-1,N-1]) <= 1.0e-20 thenOK := FALSE:else# Step 8# Start backward substitutionX[N-1] := A[N-1,M-1] / A[N-1,N-1]:# Step 9for K from 1 to NN doI1 := NN-K+1:JJ := I1+1:SUM := 0:for KK from JJ to N doSUM := SUM - A[I1-1,KK-1] * X[KK-1]:od:X[I1-1] := (A[I1-1,M-1]+SUM) / A[I1-1,I1-1]:od:# Step 10# Process is completeprint(`Choice of output method`):print(`1. Output to screen`):print(`2. Output to text file`):print(`Please enter 1 or 2.`):FLAG := scanf(`%d`)[1]: print(`Your input is`): print(FLAG):if FLAG = 2 thenprint(`Input the file name in the form - drive:\134\134name.ext`):print(`for example: A:\134\134OUTPUT.DTA`):NAME := scanf(`%s`)[1]: print(`The output file is`): print(NAME):OUP := fopen(NAME, WRITE,TEXT):elseOUP := default:fi:fprintf(OUP, `GAUSSIAN ELIMINATION\134n\134n`):fprintf(OUP, `The reduced system - output by rows:\134n`):for I1 from 1 to N dofor J from 1 to M dofprintf(OUP, ` %11.8f`, A[I1-1,J-1]):od:fprintf(OUP, `\134n`):od:fprintf(OUP, `\134n\134nHas solution vector:\134n`):for I1 from 1 to N dofprintf(OUP, ` %12.8f`, X[I1-1]):od:fprintf (OUP, `\134n\134nwith %d row interchange(s)\134n`, ICHG):if OUP <> default thenfclose(OUP):print(`Output file `,NAME,` created successfully`):fi:fi:fi:if OK = FALSE thenprint(`System has no unique solution\134n`):fi:fi:JSFH