Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Program counters

Status
Not open for further replies.

dannyf

Technical User
Joined
Mar 30, 2001
Messages
3
Location
MC
If I have a program like the one shown below and i execute the program 5 times. Each time I execute the program, it will print a number 'x' to the screen. Is there any code I could write to add up the numbers which are printed to the screen each time the program is executed.

Program Sum
Implicit None
Integer :: x,n
print*,type in a value for n
read*,n

x = n + 1

print*,x

End Program Sum
 
c Why not save the sum in a file (SUM) ?
c program savesum
integer oldsum /0/ , x
logical sumfile
inquire (file="SUM",exist=sumfile)
open(7,file="SUM")
if(sumfile) then
c A sum already exists , read it :
read(7,*) oldsum
rewind 7
end if
c ....................
c compute x
c ....................
newsum = x + oldsum
write(7,*) newsum
close (7)
end

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top