怎样用fortran求两个数的最大公因数
来源:学生作业帮 编辑:拍题作业网作业帮 分类:数学作业 时间:2024/04/30 23:44:11
怎样用fortran求两个数的最大公因数
program main
!辗转相除法
integer m,n
common m,n
print*,'Please input two positive integers:'
read(*,*) m,n
call Euclid(m,n)
endprogram
subroutine Euclid(m,n)
integer r
do while(n.ne.0)
r = mod(m,n)
m = n
n = r
enddo
print*,'Their greatest common divisor is', m
endsubroutine
!辗转相除法
integer m,n
common m,n
print*,'Please input two positive integers:'
read(*,*) m,n
call Euclid(m,n)
endprogram
subroutine Euclid(m,n)
integer r
do while(n.ne.0)
r = mod(m,n)
m = n
n = r
enddo
print*,'Their greatest common divisor is', m
endsubroutine