Fortran: Lesson 4

Lesson topics


View Demos
# 1 # 2 # 3 # 4 # 5 # 6
Download Demos
# 1 # 2 # 3 # 4 # 5 # 6

Demo 3

								        program sumofpowers
c       This program computes sums of powers of integers.
        integer n, m
        real p, sum
        print *, "Enter a positive integer :"
        read *, n
        print *, "Enter a power p :"
        read *, p

        sum = 0
        m = 1
        do while (m .le. n)
                sum = sum + m**p
                m = m + 1
        end do

        print *
        print *, "The sum of the integers to the power", p
        print *, "from 1 to", n, " is", sum
        print *
        print *, "Bye"
        end