Skip to content

Instantly share code, notes, and snippets.

@komasaru komasaru/gcd.f95
Last active Nov 13, 2018

Embed
What would you like to do?
Fortran 95 source code to compute the G.C.D.
!****************************************************
! 最大公約数計算
!
! date name version
! 2018.08.20 mk-mode.com 1.00 新規作成
!
! Copyright(C) 2018 mk-mode.com All Rights Reserved.
!****************************************************
!
program gcd_main
implicit none
write (*,*) gcd(144, 300)
stop
contains
! 最大公約数計算
!
! :param integer a
! :param integer b
! :return integer gcc
integer function gcd(a, b)
implicit none
integer, intent(IN) :: a, b
integer :: l, m, n
m = a
n = b
do
l = mod(m, n)
if (l == 0) exit
m = n
n = l
end do
gcd = n
return
end function gcd
end program gcd_main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.