program hanoimain ! recursive towers of hanoi program in ! fortran 90 integer n n = 5 call hanoi(n,'a','c','b') end ! recursive subroutine hanoi(n,frompeg,auxpeg,topeg) integer n character*1 frompeg,auxpeg,topeg if (n == 1) then write(6,*)"Move disk 1 from peg ", frompeg, " to peg ", topeg else call hanoi(n-1,frompeg,auxpeg,topeg) write(6,101) n, frompeg,topeg 101 FORMAT(1x,"Move disk ",i1," from peg ", A1, " to peg ", A1) call hanoi(n-1,auxpeg,topeg,frompeg) endif end