How to resolve the algorithm Sum of squares step by step in the Seed7 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Sum of squares step by step in the Seed7 programming language

Table of Contents

Problem Statement

Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0).

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Sum of squares step by step in the Seed7 programming language

Source code in the seed7 programming language

$ include "seed7_05.s7i";
  include "float.s7i";
 
const array float: list1 is [] (3.0, 1.0, 4.0, 1.0, 5.0, 9.0);
const array float: list2 is 0 times 0.0;

const func float: squaredSum (in array float: floatList) is func
  result
    var float: sum is 0.0;
  local
    var float: number is 0.0;
  begin
    for number range floatList do
      sum +:= number ** 2;
    end for;
  end func;
 
const proc: main is func
  begin
    writeln(squaredSum(list1));
    writeln(squaredSum(list2));
  end func;

  

You may also check:How to resolve the algorithm Galton box animation step by step in the Ruby programming language
You may also check:How to resolve the algorithm Arithmetic/Integer step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Null object step by step in the Standard ML programming language
You may also check:How to resolve the algorithm Draw a cuboid step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Dining philosophers step by step in the Rust programming language