---
title: "Series sum 1/1¹+1/2²+… in FORTRAN"
subject: "Computer Programming"
chapter: 11
key: "semester_1/computer_programming:fortran-series-sum-1-over-n"
source: https://www.bctengineer.com/q/semester_1/computer_programming/fortran-series-sum-1-over-n
site: BCT Engineering
---

# Series sum 1/1¹+1/2²+… in FORTRAN

Computer Programming · Chapter 11: Programming Language: FORTRAN

- Asked in: 2067 Asar, 8 marks
- Video: [FORTRAN 90 PROGRAMMING TUTORIAL| How to compute and print sum of the sequence of numbers in Fortran](https://www.youtube.com/watch?v=rRjhXbEQ-Rk) — Maths is fun by Sana Sultana 
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/fortran-series-sum-1-over-n
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-11

## Question

Write a program in FORTRAN to evaluate the following series:
series = 1/1¹ + 1/2² + 1/3² + ... ... + 1/n²

## Short answer

Loop k from 1 to n, adding 1.0/(k*k) to sum. Use 1.0 for real division. For n=5 sum ≈ 1.463611; for n=10 sum ≈ 1.549768.

## Answer

**Reading of the question.** The series is written as 1/1¹ + 1/2² + 1/3² + …, whose general term is 1/k² (the first term is 1 whichever way it is read). So the program finds S = Σ 1/k² for k = 1 to n.

```fortran
      PROGRAM SERIES2
      INTEGER N, K
      REAL S
      PRINT *, 'ENTER NUMBER OF TERMS'
      READ *, N
      S = 0.0
      DO 10 K = 1, N
         S = S + 1.0 / (K * K)
   10 CONTINUE
      WRITE(*,20) N, S
   20 FORMAT(' SUM OF FIRST ', I3, ' TERMS = ', F10.6)
      STOP
      END
```

`K*K` is an integer product and `1.0 / (K*K)` is real division, so the fraction is not lost.

**Sample values (calculated separately):** n = 5 gives 1.463611 and n = 10 gives 1.549768. The sum approaches π²/6 = 1.644934 as n grows.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What is the general term used for the series?
   A. 1/k^2
   B. 1/k
   C. k^2
   D. 1/2^k
   Answer: A. The series 1/1 + 1/2^2 + 1/3^2 + ... has term 1/k^2. (Key point: General term)

2. Why is 1.0 / (K*K) written with 1.0?
   A. To force real division so the fraction is not truncated to 0
   B. To print decimals
   C. To make K real
   D. It is optional
   Answer: A. K*K is an integer; 1/(K*K) in integers gives 0 for K > 1, while 1.0 makes it real. (Key point: Real division)

3. How is the total built?
   A. S = S + 1.0/(K*K) in a loop from 1 to N after S = 0.0
   B. S = 1.0/(N*N)
   C. S = S * K
   D. S = K + N
   Answer: A. The sum starts at zero and each term is added in the DO loop. (Key point: Accumulation)

4. Towards what value does the sum approach as n grows?
   A. pi^2/6 = 1.644934
   B. 1
   C. infinity
   D. pi
   Answer: A. The sum of 1/k^2 converges to pi^2/6. (Key point: Limit)

## Related in Computer Programming

- [GOTO types; sum of series program](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-goto-types-series) — Computer Programming, chapter 11
- [Sum of two matrices in FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-matrix-sum) — Computer Programming, chapter 11
- [Structure of a FORTRAN program](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-structure) — Computer Programming, chapter 11, asked 5×
- [Sum of series Σ1/n²](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aseries-sum-1-n-squared) — Computer Programming, chapter 5
- [Sort array ascending in FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-sort-ascending) — Computer Programming, chapter 11, asked 2×
- [Quadratic equation roots in FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-quadratic-roots) — Computer Programming, chapter 11, asked 2×

## Related in other subjects

- [C program: sum of two 8-bit BCD numbers](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3A8051-bcd-sum-c) — Embedded System, chapter 9
- [Series sum using Z-transform](https://www.bctengineer.com/question.md?key=semester_3%2Fmathematics_iii%3Aseries-sum-using-z-transform) — Mathematics III, chapter 3
- [Program for RK-4 first order IVP](https://www.bctengineer.com/question.md?key=semester_4%2Fnumerical_method%3Ark4-program-first-order) — Numerical Method, chapter 6
- [Program for RK-4 second order IVP](https://www.bctengineer.com/question.md?key=semester_4%2Fnumerical_method%3Ark4-program-second-order) — Numerical Method, chapter 6
