Ordering statements to swap two values

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. 1.

    print *, x, y

  2. 2.

    y = temp

  3. 3.

    temp = x

  4. 4.

    read *, x, y

  5. 5.

    x = y

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Fortran and Other Imperative Languages Questions: