- 2067 Asar · 8 marks
Series sum 1/1¹+1/2²+… in FORTRAN
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.
Write a program in FORTRAN to evaluate the following series: series = 1/1¹ + 1/2² + 1/3² + ... ... + 1/n²
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.
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.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- GOTO types; sum of series program · Computer Programming, chapter 11
- Sum of two matrices in FORTRAN · Computer Programming, chapter 11
- Structure of a FORTRAN program · Computer Programming, chapter 11 · asked 5×
- Sum of series Σ1/n² · Computer Programming, chapter 5
- Sort array ascending in FORTRAN · Computer Programming, chapter 11 · asked 2×
- Quadratic equation roots in FORTRAN · Computer Programming, chapter 11 · asked 2×
- C program: sum of two 8-bit BCD numbers · Embedded System, chapter 9
- Series sum using Z-transform · Mathematics III, chapter 3
- Program for RK-4 first order IVP · Numerical Method, chapter 6
- Program for RK-4 second order IVP · Numerical Method, chapter 6