Fortran: Lesson 2

Lesson topics


View Demos
# 1 # 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 10
Download Demos
# 1 # 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 10

Demo 9

								        program addpowers
c       This program adds powers of integers from 1 to n.
c       The user inputs the power and the integer n.
        real sum, power
        integer i, n
        print *, "Enter a power : "
        read *, power
        print *, "At what integer n do you wish to stop the sum ?"
        read *, n
        sum = 0
        do i = 1, n
                sum = sum + i ** power
        end do
        print *
        print *, "Here is the sum of the integers to the power", power
        print *, "from i = 1 to i = ", n, ":", sum
        end