|
Revision 1262, 497 bytes
(checked in by mswat, 2 years ago)
|
|
|
| Line | |
|---|
| 1 | ! sum.f90
|
|---|
| 2 | ! Performs summations using in a loop using EXIT statement
|
|---|
| 3 | ! Saves inputted 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
|
|---|