Advertisement
Guest User

Untitled

a guest
Oct 6th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. subroutine printArr(array)
  2.   integer, intent(in) :: array(4,4)
  3.   integer i
  4.     do i=1,4
  5.       write (*,*)  (array(i,j),j=1,4)
  6.     end do
  7.   write (*,*)
  8. end subroutine printArr
  9.  
  10. subroutine first(num,oldArray, newArray)
  11. implicit none
  12.   integer,intent(in) :: num
  13.   integer,intent(in) :: oldArray(4,4)
  14.   integer,intent(out) :: newArray(4,4)
  15.   integer i,j
  16.   select case (num)
  17.    
  18.     case (1)
  19.       newArray=oldArray
  20.       do i= 1,3
  21.       do j = i+1,4
  22.           newArray(i,j)=newArray(i,j-1)+1
  23.     end do
  24.       end do
  25.  
  26.     case (2)
  27.       newArray=oldArray
  28.  
  29.     case (3)
  30.       newArray=oldArray
  31.       do i= 1,3
  32.       do j = i+1,4
  33.           newArray(i,j)=newArray(i,j-1)+1
  34.     end do
  35.       end do
  36.  
  37.     case (4:7)
  38.     newArray=oldArray
  39.       do j= 1,4
  40.       do i = j+1,4
  41.           newArray(i,j)=newArray(i-1,j)+1
  42.     end do
  43.       end do
  44.  
  45.     case (8:10)
  46.       do i=1,4
  47.     do j=1,4
  48.       newArray(i,j)=0
  49.     end do
  50.       end do
  51.      
  52.  
  53.   end select
  54. return
  55. end subroutine first
  56.  
  57. subroutine second(array,row,column,theRow,theColumn)
  58.   implicit none
  59.   integer , intent(in):: array(4,4)
  60.   integer ,intent(in):: row
  61.   integer ,intent(in):: column
  62.   integer ,intent(out) :: theRow(4)
  63.   integer ,intent(out) :: theColumn(4)
  64.  
  65.   theRow= array(row,1:4)
  66.   theColumn= (/ array(1,column), array(2,column), array(3,column), array(4,column) /)
  67.   return
  68. end subroutine second
  69.  
  70. Program matrix
  71. implicit none
  72.   integer tempArray(4,4)
  73.   integer theMatrix(4,4)
  74.   integer p,q,i,j,r
  75.   integer myRow(4)
  76.   integer myColumn(4)
  77.  
  78.  
  79.   do i=1,4
  80.     do j=1,4
  81.       theMatrix(i,j)=0
  82.     end do
  83.   end do
  84.  
  85.   theMatrix(1,1) =1
  86.   theMatrix(2,2) =1
  87.   theMatrix(3,3) =1
  88.   theMatrix(4,4) =1
  89.  
  90.  
  91.  
  92.   call printArr(theMatrix)
  93.  
  94.   print *, "First Subroutine"
  95.   print *, "Enter a number between 1 and 10"
  96.  
  97.  
  98.   read (*,*) p
  99.   call first(p,theMatrix,tempArray)
  100.  
  101.  
  102.   theMatrix=tempArray
  103.   call printArr(theMatrix)
  104.  
  105.   print *, "Second Subroutine"
  106.   print *, "Enter a row and column number that u want (1->4)"
  107.  
  108.   read (*,*) q,r
  109.  
  110.   call second(theMatrix,q,r,myRow,myColumn)
  111.  
  112.   write (*,*) myRow
  113.   write (*,*)
  114.   write (*,*) myColumn(1)
  115.   write (*,*) myColumn(2)
  116.   write (*,*) myColumn(3)
  117.   write (*,*) myColumn(4)
  118.  
  119.  
  120. end program matrix
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement