*INTITIALIZE
M = 0
N = 0
J = 0
I = 0
K = 0
DONE = 1
VALID = 1
M = 0
N = 0
J = 0
I = 0
K = 0
DONE = 1
VALID = 1
*LOOP UNTIL USER CHOOSES TO QUIT
DO WHILE(DONE .GT. 0)
*DISPLAY MENU UNTIL VALID ENTRY IS ENTERED
DO WHILE (VALID .GT. 0)
*PRINT MENU
PRINT *,'MATRIX CALCULATOR'
PRINT *,'PLEASE MAKE A SELECTION'
PRINT *,'1) MATRIX ADDITION'
PRINT *,'2) MATRIX SUBTRACTION'
PRINT *,'3) MATRIX MULTIPLICATION'
PRINT *,'4) MATRIX TRANSPOSE'
PRINT *,'5) QUIT PROGRAM'
READ (*,*) SELECTION
*PRINT MENU
PRINT *,'MATRIX CALCULATOR'
PRINT *,'PLEASE MAKE A SELECTION'
PRINT *,'1) MATRIX ADDITION'
PRINT *,'2) MATRIX SUBTRACTION'
PRINT *,'3) MATRIX MULTIPLICATION'
PRINT *,'4) MATRIX TRANSPOSE'
PRINT *,'5) QUIT PROGRAM'
READ (*,*) SELECTION
*VALID ENTRY CHECK
IF (SELECTION .GT. 5 .OR. SELECTION .LT. 1) THEN
PRINT *,'PLEASE ENTER A VALID SELECTION'
ELSE
VALID= -1
END IF
IF (SELECTION .GT. 5 .OR. SELECTION .LT. 1) THEN
PRINT *,'PLEASE ENTER A VALID SELECTION'
ELSE
VALID= -1
END IF
*END WHEN VALID ENTRY IS ENTERED
END DO
END DO
*QUIT?
IF (SELECTION .EQ. 5) THEN
DONE = -1
ELSE
*OTHERWISE CONTINUE
*GET DIMENTIONS INPUT
PRINT *,'PLEASE ENTER THE DIMENTIONS'
PRINT *,'ENTER IN M:'
READ (*,*) M
PRINT *,'ENTER IN N:'
READ (*,*) N
*GET IN MATRIX
PRINT *, 'PLEASE ENTER IN MATRIX A'
DO J=1, M
DO I=1, N
PRINT *, 'ENTER IN VALUE I, I', J, I
READ(*,*) A(M,N)
END DO
END DO
IF (SELECTION .EQ. 5) THEN
DONE = -1
ELSE
*OTHERWISE CONTINUE
*GET DIMENTIONS INPUT
PRINT *,'PLEASE ENTER THE DIMENTIONS'
PRINT *,'ENTER IN M:'
READ (*,*) M
PRINT *,'ENTER IN N:'
READ (*,*) N
*GET IN MATRIX
PRINT *, 'PLEASE ENTER IN MATRIX A'
DO J=1, M
DO I=1, N
PRINT *, 'ENTER IN VALUE I, I', J, I
READ(*,*) A(M,N)
END DO
END DO
PRINT *, 'PLEASE ENTER IN MATRIX B'
DO J=1, M
DO I=1, N
PRINT *, 'ENTER IN VALUE I, I', J,I
READ(*,*) B(M,N)
END DO
END DO
DO J=1, M
DO I=1, N
PRINT *, 'ENTER IN VALUE I, I', J,I
READ(*,*) B(M,N)
END DO
END DO
*PERFORM DESIRED CALCULATION
SELECT CASE(SELECTION)
*CASE 1
CASE (1)
PRINT *,'MATRIX ADDITION'
DO J=1,M
DO I=1,N
SUM(J,I)=A(J,I)+B(J,I)
END DO
END DO
SELECT CASE(SELECTION)
*CASE 1
CASE (1)
PRINT *,'MATRIX ADDITION'
DO J=1,M
DO I=1,N
SUM(J,I)=A(J,I)+B(J,I)
END DO
END DO
*PRINT ADDITION RESULT
PRINT *,'ADDITION RESULT'
DO J=1, M
DO I=1, N
WRITE (*,*) SUM(J,I)
END DO
END DO
*CASE 2
CASE (2)
PRINT *,'MATRIX SUBTRACTION'
DO J=1,M
DO I=1,N
SUM(J,I)=A(J,I)-B(J,I)
END DO
END DO
PRINT *,'ADDITION RESULT'
DO J=1, M
DO I=1, N
WRITE (*,*) SUM(J,I)
END DO
END DO
*CASE 2
CASE (2)
PRINT *,'MATRIX SUBTRACTION'
DO J=1,M
DO I=1,N
SUM(J,I)=A(J,I)-B(J,I)
END DO
END DO
*PRINT SUBTRACTION RESULT
PRINT *,'SUBTRACTION RESULT'
DO J=1, M
DO I=1, N
WRITE (*,*) SUM(J,I)
END DO
END DO
*CASE 3
CASE (3)
PRINT *,'MATRIX MULTIPLICATION'
DO J=1, M
DO I=1, N
DO K=1, N
SUM(J,I) = SUM(J,I)+A(J,K)*B(I,J)
END DO
END DO
END DO
PRINT *,'SUBTRACTION RESULT'
DO J=1, M
DO I=1, N
WRITE (*,*) SUM(J,I)
END DO
END DO
*CASE 3
CASE (3)
PRINT *,'MATRIX MULTIPLICATION'
DO J=1, M
DO I=1, N
DO K=1, N
SUM(J,I) = SUM(J,I)+A(J,K)*B(I,J)
END DO
END DO
END DO
*PRINT MULTIPLICATION RESULT
DO J=1, M
DO I=1, N
WRITE (*,*) SUM(J,I)
END DO
END DO
*CASE 4
CASE (4)
PRINT *,'MATRIX TRANSPOSE'
DO J=1, M
DO I=1, N
B(I,J) = A(J,I)
END DO
END DO
*PRINT TRANSPOSE RESULT
PRINT *, 'MATRIX A RESULT'
DO J=1, M
DO I=1, N
WRITE (*,*) A(J,I)
END DO
END DO
PRINT *, 'MATRIX B RESULT'
DO J=1, M
DO I=1, N
WRITE (*,*) B(J,I)
END DO
END DO
CASE DEFAULT
PRINT *,'SOMETHING HAS GONE WRONG'
END SELECT
DO J=1, M
DO I=1, N
WRITE (*,*) SUM(J,I)
END DO
END DO
*CASE 4
CASE (4)
PRINT *,'MATRIX TRANSPOSE'
DO J=1, M
DO I=1, N
B(I,J) = A(J,I)
END DO
END DO
*PRINT TRANSPOSE RESULT
PRINT *, 'MATRIX A RESULT'
DO J=1, M
DO I=1, N
WRITE (*,*) A(J,I)
END DO
END DO
PRINT *, 'MATRIX B RESULT'
DO J=1, M
DO I=1, N
WRITE (*,*) B(J,I)
END DO
END DO
CASE DEFAULT
PRINT *,'SOMETHING HAS GONE WRONG'
END SELECT
*USER SELECTED TO QUIT
END IF
END DO
PRINT *, 'PROGRAM HAS ENDED'
*END PROGRAM
STOP
END
END IF
END DO
PRINT *, 'PROGRAM HAS ENDED'
*END PROGRAM
STOP
END
No comments:
Post a Comment