Advertisement
mannaf

summation

May 6th, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ! sum.f90
  2. ! Performs summations using in a loop using EXIT statement
  3. ! Saves input information and the summation in a data file
  4.  
  5. program summation
  6. implicit none
  7. integer :: sum, a
  8.  
  9. print*, "This program performs summations. Enter 0 to stop."
  10. open(unit=10, file="SumData.DAT")
  11.  
  12. sum = 0
  13.  
  14. do
  15.  print*, "Add:"
  16.  read*, a
  17.  if (a == 0) then
  18.   exit
  19.  else
  20.   sum = sum + a
  21.  end if
  22.  write(10,*) a
  23. end do
  24.  
  25. print*, "Summation =", sum
  26. write(10,*) "Summation =", sum
  27. close(10)
  28.  
  29. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement