summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2017-11-17 12:21:14 +0300
committerIgor Pashev <pashev.igor@gmail.com>2017-11-17 12:21:14 +0300
commitdcb6e60f9b1f2ef0e853c64534caea42e20ed87b (patch)
treec5ab63207825e59f2674a031a36dbd473acc3482
parent0b0c13b1cdf0427f604ff3e1df8963df7237a527 (diff)
downloadgcd-dcb6e60f9b1f2ef0e853c64534caea42e20ed87b.tar.gz
fprettify -i 2 gcd.f03
https://pypi.python.org/pypi/fprettify
-rw-r--r--gcd.f0339
1 files changed, 19 insertions, 20 deletions
diff --git a/gcd.f03 b/gcd.f03
index f1f144f..c2c585d 100644
--- a/gcd.f03
+++ b/gcd.f03
@@ -5,25 +5,24 @@
!
program GCD
-implicit none
+ implicit none
-integer, allocatable :: ns(:)
-integer :: i, n
-character*20 :: tmpstr
+ integer, allocatable :: ns(:)
+ integer :: i, n
+ character*20 :: tmpstr
-n = command_argument_count()
+ n = command_argument_count()
-allocate(ns(n)) ! allocate memory for numbers given in command line
+ allocate (ns(n)) ! allocate memory for numbers given in command line
-do i = 1, n
+ do i = 1, n
call get_command_argument(i, tmpstr)
ns(i) = str2int(tmpstr)
-end do
+ end do
-print *, gcdn(ns)
-
-deallocate(ns)
+ print *, gcdn(ns)
+ deallocate (ns)
! If we declare functions first,
! we have to specify its types within
@@ -31,27 +30,27 @@ deallocate(ns)
! See http://en.wikibooks.org/wiki/Fortran/Fortran_procedures_and_functions
contains
-pure integer function str2int (s)
+ pure integer function str2int(s)
character*(*), intent(in) :: s
read (s, *) str2int
-end function
+ end function
-pure recursive integer function gcd2 (a, b) result(GCD)
+ pure recursive integer function gcd2(a, b) result(GCD)
integer, intent(in) :: a, b
if (b == 0) then
- GCD = a
+ GCD = a
else
- GCD = gcd2(b, mod(a, b))
+ GCD = gcd2(b, mod(a, b))
end if
-end function gcd2
+ end function gcd2
-pure integer function gcdn(n)
+ pure integer function gcdn(n)
integer, intent(in) :: n(:) ! n is an array
integer :: i
gcdn = n(1)
do i = 2, size(n)
- gcdn = gcd2(gcdn, n(i))
+ gcdn = gcd2(gcdn, n(i))
end do
-end function
+ end function
end program