A Fortran program must read two integers into x and y, exchange their values using a third integer variable temp, and then print the exchanged pair. Arrange the statements below into the only order that works correctly for every possible input.
1.
print *, x, y
2.
y = temp
3.
temp = x
4.
read *, x, y
5.
x = y
Unlock full course notes by signing up
Final state after a condition-controlled digit loop
The Fortran program below repeats its loop body while a condition holds rather than for a fixed count. The intrinsic function mod(n, 10) returns the remainder when n is divided by 10, and n / 10 is integer division because both operands are integers.
Give the values of s, c and n that the print statement displays, each as a whole number.
Column-major storage of a Fortran array
A Fortran program declares the array integer :: a(2, 3), which has 2 rows and 3 columns, with subscripts starting at 1. Fortran stores a multidimensional array in column-major order: the elements of the first column come first, then the second column, so the first subscript varies fastest. Languages such as C store the same shape row by row, so the last subscript varies fastest. Counting the first stored element as position 1, fill in the memory position of each element under both layouts, as whole numbers.
Output of nested loops with a moving start
In the Fortran program below, i, j and total are integers. Note that the inner loop starts at the current value of i, not at 1. What integer value does the program print? Give your answer as a whole number.