Skip to main content
Engineering LibreTexts

13.9: Exercises

  • Page ID
    54352
  • \( \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. Explain why an array is considered a direct access structure.
    2. Can arrays hold integer values (yes/no)?
    3. Can arrays hold real values (yes/no)?
    4. Write the declarations for the following:
      1. An integer constant, SIZE1, set to 100.
      2. An array, rvalues, with 10 real elements.
      3. An array, inums, with SIZE1 integer arguments.
      4. An array, counts, with 10 real elements whose subscript values range from 0 to 9.
    5. Given the declarations and the following code:
      integer, dimension(4) :: arr
      integer :: k
      
      arr(1) = 10
      arr(2) = 15
      arr(3) = 20
      arr(4) = 25
      k=3
      1. What does arr(1) equal?
      2. What does arr(1) + arr(2) equal?
      3. What does arr(1+2) equal?
      4. What does arr(k) equal?
    6. When can an array be allocated (two options)?
    7. Given the following statements:
      integer, dimension(5) :: nums
      integer :: i=1
      
      nums = 0
      
      do
          if ( i == 5 ) exit
          if ( mod(i,2) == 0) then
              nums(i) = 99
          else
              nums(i) = i
          end if
          i = i + 1
      end do
      1. What values are in the array after execution?
      2. What is the (nums(i), i=1,5) referred to as?
      3. What does write (*,'(1x,i2)') (nums(i), i=1,5) display? Note: use an underscore (“_”) to show the spaces.

    Suggested Projects

    Below are some suggested projects.

    1. Type in the standard deviation program, compile, and execute the program. Test the program on a series of different input values.
    2. Write a Fortran program to cube a series of integer numbers from a file and cube each number. The program should also calculate the real average of the original numbers and the real average of the cubed numbers. Test the program on a series of different input values.
    3. Write a Fortran program to generate a series of real values between 1.0 and 100.0 and store the numbers in an array. Then, the program should compute the norm of a vector (single dimension array). The formula for norm is as follows:\[ \left| \textit{norm} \right| = \sqrt{a_1^2 + a_2^2 + a_3^2 + \ldots + a_n^2} \nonumber \]Refer to Appendix C for more information regarding generating random numbers. Test the program on a series of different input values.
    4. Write a Fortran program to read a series of numbers from a file, store the numbers in an array, and then sort the numbers using the following selection sort algorithm:
      for i = len downto 1
          big = arr(1)
          index = 1
          for j = 1 to i
              if arr(j) > big
                  big = arr(j)
                  index = j
              end_if
          end_for
          arr(index) = arr(i)
          arr(i) = big
      end_for
      You will need to convert the above pseudo-code algorithm into Fortran code. Test the program on a series of different input values.

    This page titled 13.9: 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?