Skip to main content
Engineering LibreTexts

14.5: Exercises

  • Page ID
    54356
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Below are some quiz questions and project suggestions based on this chapter.

    Quiz Questions

    Below are some quiz questions.

    1. Can a multidimensional array simultaneously hold both integer and real values (yes/no)?
    2. Multiple choice: what is the order of the indexes?
      1. (row, column)
      2. (column, row)
      3. (row, row)
      4. (column, column)
      5. user-selectable
      Note, there is only one correct answer.
    3. Given the following code:
      real, dimension(5,3) :: mdarr
      integer :: i, j
      
      do i = 1, 5
          do j = 1, 3
              mdarr(i,j) = real(i+j)
          end do
      end do
      1. How many values, total, can be stored in the mdarr array?
      2. Show the contents of every cell in the mdarr.
      3. What does mdarr(2,1) contain?
      4. What does mdarr(1,3) contain?
      5. What does mdarr(4,3) contain?
    4. How can an unsuccessful multidimensional dynamic allocation be detected?

    Suggested Projects

    Below are some suggested projects.

    1. Type in the \(\pi\) estimation program, compile, and execute the program. Test the program on a series of different point count values. Demonstrate that larger point values provide a better estimation.
    2. Update the \(\pi\) estimation program to ensure that a valid count value is obtained within three tries. If there are more than three errors, the program should display an error message and terminate.
    3. Update the \(\pi\) estimation program to display the estimated \(\pi\) value 10 times. In order to perform this, the count value can be divided by 10 and the current estimated \(\pi\) value displayed.
    4. Write a program to statically declare a 100x100 two-dimensional array of real values. The program should populate the array with random numbers between 0 (inclusive) and 1 (exclusive). Refer to Appendix C for information regarding generating random numbers. The program should scan the array to find and display the maximum value and the location of that value (i.e., the row and column where the value was found).
    5. Update the find maximum program (from the previous question) to declare the array dynamically and allow the user to enter the row and column dimensions and ensure that each is between 10 and 1000. Once entered, the program should allocate the array and find and display the maximum and minimum values and their locations (row and column).
    6. Write a Fortran program to construct an odd-order Magic Square1. The algorithm for constructing a NxN odd ordered Magic Square is as follows:
      1. First, place a 1 in the middle of the top row.
      2. After placing an integer, \(k\), move up one row and one column to the right to place the next integer, \(k+1\), unless the following occurs:
        1. If a move takes you above the top row in the jth column, move to the bottom of the jth column and place the integer there.
        2. If a move takes you outside to the right of the square in the ith row, place the integer in the ith row at the left side.
        3. If a move takes you to an already filled square or if you move out of the square at the upper right hand corner, place \(k+1\) immediately below \(k\).
      Test the program and compare the results to the Wikipedia example.

    1. For more information, refer to: http://en.Wikipedia.org/wiki/Magic_square

    This page titled 14.5: Exercises is shared under a CC BY-NC-SA 3.0 license and was authored, remixed, and/or curated by Ed Jorgensen via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.

    • Was this article helpful?