Να γραφεί πρόγραμμα που να προσθέτει
και να αφαιρεί δυο πίνακες.
Κώδικας:
PROGRAM arraysumdif
IMPLICIT NONE
INTEGER, PARAMETER:: N=2, M=2
INTEGER:: i, j, A(N,M), B(N,M), C(N,M), D(N,M)
WRITE(*,*) ' Dwse ta stoixeia tou Pinaka A'
READ(*,*) ((A(i,j),j=1,M),i=1,N)
WRITE(*,*) ' Dwse ta stoixeia tou Pinaka B'
READ(*,*) ((B(i,j),j=1,M),i=1,N)
!
DO i = 1, N
DO j = 1, M
C(i,j) = A(i,j) + B(i,j)
D(i,j) = B(i,j) - A(i,j)
END DO
END DO
!
WRITE(*,*) ' Pinakas A ='
DO i = 1, N
WRITE(*,*) (A(i,j),j=1,M)
END DO
WRITE(*,*) ' Pinakas B ='
DO i = 1, N
WRITE(*,*) (B(i,j),j=1,M)
END DO
WRITE(*,*) ' Athroisma C ='
DO i = 1, N
WRITE(*,*) (C(i,j),j=1,M)
END DO
WRITE(*,*) ' Diafora D ='
DO i = 1, N
WRITE(*,*) (D(i,j),j=1,M)
END DO
END
Εκτέλεση:
Dwse
ta stoixeia tou Pinaka A
1 2 3 4
Dwse
ta stoixeia tou Pinaka B
3 5 7 9
Pinakas
A =
1
2
3
4
Pinakas
B =
3
5
7
9
Athroisma
C =
4
7
10
13
Diafora
D =
2
3
4
5
|
|