13.07.2015 Views

Fortran 90/95 Programming Manual

Fortran 90/95 Programming Manual

Fortran 90/95 Programming Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Fortran</strong> <strong>90</strong>/<strong>95</strong> <strong>Programming</strong> <strong>Manual</strong>ExercisesExercise 16, the Towers of Hanoi, is optional.15. Finish the program student_list by adding to the student_class module the procedurescreate_student and delete_student.16. The Towers of Hanoi.There are three poles. One of them contains discs having different widths stacked inascending order; the other two poles are empty:The goal is to move all the discs from the centre pole and stack them on one of theother poles in ascending order. You can only move the top disc of a stack, and youcan only move one disc at a time. It is not allowed to stack a disc on top of one thatis smaller.You will have to figure out a way to represent the discs and their location, and analgorithm to move the discs. By printing the occupation of the towers after eachmove, you can check if your program works correctly.Hint: The easiest algorithm uses a recursive function. By making the towers (theirrepresentation) global (by using modules), printing becomes a lot easier!7. More on I/OList-directed input/outputIn Chapter 2 we have seen that we can transfer data from the keyboard into the programusing read * , and write characters to the screen via print * . This simple form of I/O iscalled list-directed input/output. The * in read * and print * means “free format”, that is,the format is defined by the computer system, and is not under the control of theprogrammer. More control is given to the programmer via formatted I/O.Formatted input/outputThere are two forms of formatted input. The simplest one has the form:read fmt, variable_listSimilarly, the simpler of the two forms of formatted output statements has the form:print fmt, variable_list49

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!