How to resolve the algorithm Sum of squares step by step in the MOO programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Sum of squares step by step in the MOO 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 MOO programming language
Source code in the moo programming language
@verb #100:sum_squares this none this rd
@program #100:sum_squares
sum = 0;
list = args[1];
for i in (list)
sum = sum + (i^2);
endfor
player:tell(toliteral(list), " => ", sum);
.
{{out}}
;#100:sum_squares({3,1,4,1,5,9})
{3, 1, 4, 1, 5, 9} => 133
;#100:sum_squares({})
{} => 0
You may also check:How to resolve the algorithm Decorate-sort-undecorate idiom step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Map range step by step in the REXX programming language
You may also check:How to resolve the algorithm Harshad or Niven series step by step in the Lambdatalk programming language
You may also check:How to resolve the algorithm Number names step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Nonoblock step by step in the AutoHotkey programming language