Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- subroutine printArr(array)
- integer, intent(in) :: array(4,4)
- integer i
- do i=1,4
- write (*,*) (array(i,j),j=1,4)
- end do
- write (*,*)
- end subroutine printArr
- subroutine first(num,oldArray, newArray)
- implicit none
- integer,intent(in) :: num
- integer,intent(in) :: oldArray(4,4)
- integer,intent(out) :: newArray(4,4)
- integer i,j
- select case (num)
- case (1)
- newArray=oldArray
- do i= 1,3
- do j = i+1,4
- newArray(i,j)=newArray(i,j-1)+1
- end do
- end do
- case (2)
- newArray=oldArray
- case (3)
- newArray=oldArray
- do i= 1,3
- do j = i+1,4
- newArray(i,j)=newArray(i,j-1)+1
- end do
- end do
- case (4:7)
- newArray=oldArray
- do j= 1,4
- do i = j+1,4
- newArray(i,j)=newArray(i-1,j)+1
- end do
- end do
- case (8:10)
- do i=1,4
- do j=1,4
- newArray(i,j)=0
- end do
- end do
- end select
- return
- end subroutine first
- subroutine second(array,row,column,theRow,theColumn)
- implicit none
- integer , intent(in):: array(4,4)
- integer ,intent(in):: row
- integer ,intent(in):: column
- integer ,intent(out) :: theRow(4)
- integer ,intent(out) :: theColumn(4)
- theRow= array(row,1:4)
- theColumn= (/ array(1,column), array(2,column), array(3,column), array(4,column) /)
- return
- end subroutine second
- Program matrix
- implicit none
- integer tempArray(4,4)
- integer theMatrix(4,4)
- integer p,q,i,j,r
- integer myRow(4)
- integer myColumn(4)
- do i=1,4
- do j=1,4
- theMatrix(i,j)=0
- end do
- end do
- theMatrix(1,1) =1
- theMatrix(2,2) =1
- theMatrix(3,3) =1
- theMatrix(4,4) =1
- call printArr(theMatrix)
- print *, "First Subroutine"
- print *, "Enter a number between 1 and 10"
- read (*,*) p
- call first(p,theMatrix,tempArray)
- theMatrix=tempArray
- call printArr(theMatrix)
- print *, "Second Subroutine"
- print *, "Enter a row and column number that u want (1->4)"
- read (*,*) q,r
- call second(theMatrix,q,r,myRow,myColumn)
- write (*,*) myRow
- write (*,*)
- write (*,*) myColumn(1)
- write (*,*) myColumn(2)
- write (*,*) myColumn(3)
- write (*,*) myColumn(4)
- end program matrix
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement