9.6: Exercises
- Page ID
- 54284
\( \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.
- What will happen when an exit statement is executed?
- How many exit statements can be included in a loop?
- What will happen when a cycle statement is executed?
- How many cycle statements can be included in a loop?
- If there are multiple cycle statements in a loop, which one will be executed?
- What is the output of the following Fortran statements. Assume
sum
andi
are declared as integers.sum = 0 do i = 1, 5 sum = sum + i end do write (*,*) "The SUM is:", sum
- What is the output of the following Fortran statements. Assume
i
andj
are declared as integer.write (*,*) "start" do i = 1, 3 do j = 1, 2 write (*,*) i, " * ", j, " = ", (i*j) end do end do write (*,*) "end"
- Are the following Fortran statements valid or invalid? If valid, what will happen?
do i = 3, 2 write (*,*) i end do
- Are the following Fortran statements valid or invalid? If valid, what will happen?
do i = 3, 2 if ( i == 3 ) then write (*,*) i end do end if
- What is the limit of statements that can be included in a loop?
- When IF statements (any form) are nested inside a loop, what must be done to ensure the statements are valid?
Suggested Projects
Below are some suggested projects.
- Type in the difference program, compile, and execute the program. Test the program on a series of different input values.
- Type in the date check program, compile, and execute the program. Test the program on a series of different input values.
- Write a program to calculate the range that a ball would travel when it is thrown with an initial velocity \(v_0\) and angle \(\theta\). Based on an initial velocity provided by the user, calculate the range every 5 degrees for angles between 5 and 85 degrees. If we assume negligible air friction and ignore the curvature of the earth, a ball that is thrown into the air from any point on the earth's surface will follow a parabolic flight path.
The range (distance between the initial origin and final impact) is determined by the formula: \[ \textit{range} = -\frac{2v^{2}_{0}}{g} \cos \theta \sin \theta \nonumber\]where \(v_0\) is the initial velocity of the ball, \(\theta\) is the angle of the throw, and \(g\) is the acceleration due to the earth's gravity. The value for gravity should be defined as a constant and set to \(-9.81\) meters per second.
Note, the intrinsic trigonometric functions work in radians, so the angle in degrees will need to be converted to radians for the calculations. To convert degrees to radians:\[ \textit{radians} = \textit{degrees} \left( \frac{\pi}{180} \right) \nonumber \]Test the program on a series of different input values.