c This program reads integer value n from user and c calculate 1+2+...+n while write the intermediate resuls c to a file on disk. The final result is printed on screen. program one2n_write_file write(*,*) 'What is the N for 1 + 2 + ... + N ?' read(*,*) n open(unit=10,file='detail.txt') m = 0 do i=1, n m = m + i write(10,*) 'Intermediate result at stage',i,'is',m end do close(10) write(*,*)'The final result is', m write(*,*)'Intermedaiate results can be found in detail.txt' end