Skip to content

Instantly share code, notes, and snippets.

@zrhans
Last active December 6, 2017 17:15
Show Gist options
  • Save zrhans/2011d01df40bb143e028cba27e58ceae to your computer and use it in GitHub Desktop.
Save zrhans/2011d01df40bb143e028cba27e58ceae to your computer and use it in GitHub Desktop.
program matrizes
implicit none
!Declarar vars linhas e colunas i,j
integer :: i,j
integer, dimension(3,3) :: ID3
integer, dimension(3,3) :: A !linha1 linha2 linha3
integer, dimension(3,3) :: B = reshape((/3,1,5, 9,1,7, 2,1,0/),(/3,3/))
integer, dimension(3,3) :: C
do i = 1,3 ! linhas
do j = 1, 3 ! colunas
!Lógica da matriz identidade aij = 0para todo i diferente de j
if ( i /= j ) then
id3(i,j) = 0
else
id3(i,j) = 1
end if
end do
end do
!print '(3(i3))', id3
print 100, id3
100 format(3(i3))
! reais print '(3(f8.5))', REAL(id3)
! SEGUNDO EXERCICIO, CONSTRUA A MATRIZ C = A + B
A = ID3
print *, "Matriz A:"
print 100, A
print *, "Matriz B:"
print 100, B
!calcular a C, cij = aij + bij
do i = 1,3 ! linhas
do j = 1, 3 ! colunas
c(i,j) = a(i,j) + b(i,j)
end do
end do
print *, "Matriz C:"
print 100, C
! Fontes de leitura
! https://goo.gl/bWrisc
! https://goo.gl/xLNMwq
end program matrizes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment