program one2n_write_file_format write(*,*)'what is N for 1+2+...N' read(*,*) n open(unit=10,file='mid.txt') m = 0 do i=1,n m=m+i c write(10,*)'At stage ',i,' the result is ', m write(10,100) i,m end do c write(*,*)'The final result is',m write(*,101)m write(*,*)'Intermidiate results are in mid.txt.' 100 format(1x,'At stage ',i3,' the result is ',i4) 101 format(1x,'The final result is',i4) end