How to resolve the algorithm Sum of squares step by step in the Draco programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Sum of squares step by step in the Draco 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 Draco programming language
Source code in the draco programming language
proc nonrec sum_squares([*] int arr) ulong:
ulong sum, item;
word i, len;
sum := 0;
len := dim(arr,1);
if len>0 then
for i from 0 upto len-1 do
item := |arr[i];
sum := sum + item * item
od
fi;
sum
corp
proc nonrec main() void:
type A0 = [0] int,
A1 = [1] int,
A5 = [5] int;
writeln(sum_squares(A0()));
writeln(sum_squares(A1(42)));
writeln(sum_squares(A5(1,2,3,4,5)))
corp
You may also check:How to resolve the algorithm Arithmetic/Complex step by step in the IDL programming language
You may also check:How to resolve the algorithm Sum of elements below main diagonal of matrix step by step in the Nim programming language
You may also check:How to resolve the algorithm Increment a numerical string step by step in the Erlang programming language
You may also check:How to resolve the algorithm Object serialization step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Digital root/Multiplicative digital root step by step in the REXX programming language