How to resolve the algorithm Sum of a series step by step in the Oberon-2 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Sum of a series step by step in the Oberon-2 programming language

Table of Contents

Problem Statement

Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence.
Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use:

This approximates the   zeta function   for   S=2,   whose exact value is the solution of the Basel problem.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Sum of a series step by step in the Oberon-2 programming language

Source code in the oberon-2 programming language

MODULE SS;

  IMPORT Out;

  TYPE
    RealFunc = PROCEDURE(r:REAL):REAL;

  PROCEDURE SeriesSum(k,n:LONGINT;f:RealFunc):REAL;
    VAR
      total:REAL;
      i:LONGINT;
  BEGIN
    total := 0.0;
    FOR i := k TO n DO total := total + f(i) END;
    RETURN total
  END SeriesSum;
  
  PROCEDURE OneOverKSquared(k:REAL):REAL;
  BEGIN RETURN 1.0 / (k * k)
  END OneOverKSquared;
  
BEGIN
  Out.Real(SeriesSum(1,1000,OneOverKSquared),10);
  Out.Ln;
END SS.

  

You may also check:How to resolve the algorithm Sorting algorithms/Insertion sort step by step in the Miranda programming language
You may also check:How to resolve the algorithm Ackermann function step by step in the Potion programming language
You may also check:How to resolve the algorithm Polynomial long division step by step in the Delphi programming language
You may also check:How to resolve the algorithm Arithmetic/Integer step by step in the Wart programming language
You may also check:How to resolve the algorithm Currying step by step in the Delphi programming language