program one_to_n_sub integer sum, i ,n write(*,*) 'Please tell me the number N:' read(*,*) n call adding(sum,n) open (unit=10, file='answer.txt') write(10,*) 'The answer for 1 + 2 + 3 + ... + N is :',sum write(*,*) 'The answer has been written into file answer.txt .' end subroutine adding(total,n) integer total, n, i total = 0 do i=1,n total = total + i end do end