recursive subroutine collatz_path ( n ) !*****************************************************************************80 ! !! collatz_path() uses recursion to print the path of a Collatz sequence. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 09 March 2012 ! ! Author: ! ! John Burkardt ! ! Input: ! ! integer N, the current member of the path. ! implicit none integer n write ( *, '(2x,i8)' ) n if ( n < 1 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'collatz_path(): Fatal error!' write ( *, '(a,i8,a)' ) ' Path member N = ', n, ' is not positive.' stop else if ( n == 1 ) then else if ( mod ( n, 2 ) == 0 ) then call collatz_path ( n / 2 ) else call collatz_path ( 3 * n + 1 ) end if return end