Advertisement
Oppaceted

Untitled

Mar 10th, 2023
1,053
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. program main
  3.     implicit none
  4.     integer, dimension(13) :: arr
  5.     call ReadArray(13,arr)
  6.     !arr = (/1,1,0,0,0,0,0,2,0,57,0,0,3/)
  7.     call WriteArray(13, arr)
  8.     call zero_to_end(13,arr)
  9.     call WriteArray(13, arr)
  10. end program main
  11.  
  12. subroutine zero_to_end(n,array)
  13.     integer :: n, i
  14.     integer :: array(n)
  15.     do i =1, (n-1)
  16.         call shift(n,array,i)
  17.     end do
  18. end subroutine
  19.  
  20. subroutine shift(n,array,k)
  21.     integer :: n, k, i, j, temp
  22.     integer :: array(n)
  23.     !
  24.     do j=1,(n-1)
  25.         if (array(k)==0) then
  26.             temp = array(k)
  27.             do i=k,(n-1)
  28.                 array(i) = array(i+1)
  29.             end do
  30.             array(n) = temp
  31.         end if
  32.     end do
  33. end subroutine
  34.  
  35. subroutine WriteArray(n, array)
  36.     integer :: i, n
  37.     integer, dimension(n) :: array
  38.     !
  39.     write (*,'(a5$)') 'i='
  40.     do i =1,n
  41.         write (*,'(i3$)')  i
  42.     end do
  43.     write (*,'(/a$)') '     '
  44.     !
  45.     do i =1,n
  46.         write (*,'(a3$)') 'V'
  47.     end do
  48.     write (*,'(/a5$)') 'a[i]= '
  49.     !
  50.     do i =1,n
  51.         write (*,'(i3$)')  array(i)
  52.     end do
  53.     write (*,'(/)')
  54. end subroutine
  55.  
  56. subroutine ReadArray(n,array)
  57.     integer :: i
  58.     integer, dimension(n) :: array
  59.     do i =1,13
  60.         write (*,'(i2a$)') i,':'
  61.         read (*,*) array(i)
  62.     end do
  63. end subroutine
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement