| 1 |
C https://en.wikibooks.org/wiki/Fortran/Fortran_examples |
| 2 |
! sum.f90 |
| 3 |
! Performs summations using in a loop using EXIT statement |
| 4 |
! Saves input information and the summation in a data file |
| 5 |
|
| 6 |
program summation |
| 7 |
implicit none |
| 8 |
integer :: sum, a |
| 9 |
|
| 10 |
print *, "This program performs summations. Enter 0 to stop." |
| 11 |
open (unit=10, file="SumData.DAT") |
| 12 |
sum = 0 |
| 13 |
do |
| 14 |
print *, "Add:" |
| 15 |
read *, a |
| 16 |
if (a == 0) then |
| 17 |
exit |
| 18 |
else |
| 19 |
sum = sum + a |
| 20 |
end if |
| 21 |
write (10,*) a |
| 22 |
end do |
| 23 |
|
| 24 |
print *, "Summation =", sum |
| 25 |
write (10,*) "Summation =", sum |
| 26 |
close(10) |
| 27 |
end |
| 28 |
|