We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Yes Fortran can accept an undeclared size array as an argument, reducing the "ceremony" needed
integer function find_gcd(nums) integer, intent(in) :: nums(:) find_gcd = gcd(minval(nums), maxval(nums)) end function
Also, a working program can be declared that declares and calls gcd() in a single file, without having to define modules etc.
gcd()
Below is some skeleton code for how to do this:
program LeetCode_0255 implicit none integer, allocatable :: array(:) array = [2, 5, 6, 9,10] print *, find_gcd(array) contains integer function find_gcd(nums) integer, intent(in) :: nums(:) find_gcd = gcd(minval(nums), maxval(nums)) end function function gcd(m, n) result(answer) integer, intent(in) :: m, n integer :: answer, irest, ifirst ifirst = iabs(m) answer = iabs(n) if (answer == 0) then answer = ifirst else do irest = mod(ifirst, answer) if (irest == 0) exit ifirst = answer answer = irest enddo answer = iabs(answer) endif end function end program
Note that since the program declares implicit none, it can be omitted from the function definitions.
implicit none
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Yes Fortran can accept an undeclared size array as an argument, reducing the "ceremony" needed
Also, a working program can be declared that declares and calls
gcd()
in a single file, without having to define modules etc.Below is some skeleton code for how to do this:
Note that since the program declares
implicit none
, it can be omitted from the function definitions.The text was updated successfully, but these errors were encountered: