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.


fortran
program nested_sum
  implicit none
  integer :: i, j, total
  total = 0
  do i = 1, 4
     do j = i, 4
        total = total + j
     end do
  end do
  print *, total
end program nested_sum

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: