怎样用fortran求两个数的最大公因数
来源:学生作业帮 编辑:神马作文网作业帮 分类:数学作业 时间:2024/09/29 05:28:55
怎样用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