Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
27
Task/Permutations/Fortran/permutations-2.f
Normal file
27
Task/Permutations/Fortran/permutations-2.f
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
program allperm
|
||||
implicit none
|
||||
integer :: n, i
|
||||
integer, allocatable :: a(:)
|
||||
read *, n
|
||||
allocate(a(n))
|
||||
a = [ (i, i = 1, n) ]
|
||||
call perm(1)
|
||||
deallocate(a)
|
||||
contains
|
||||
recursive subroutine perm(i)
|
||||
integer :: i, j, t
|
||||
if (i == n) then
|
||||
print *, a
|
||||
else
|
||||
do j = i, n
|
||||
t = a(i)
|
||||
a(i) = a(j)
|
||||
a(j) = t
|
||||
call perm(i + 1)
|
||||
t = a(i)
|
||||
a(i) = a(j)
|
||||
a(j) = t
|
||||
end do
|
||||
end if
|
||||
end subroutine
|
||||
end program
|
||||
Loading…
Add table
Add a link
Reference in a new issue