How to resolve the algorithm Sum of squares step by step in the Red programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Sum of squares step by step in the Red 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 Red programming language
Source code in the red programming language
Red [
date: 2021-10-25
red-version: 0.6.4
description: "Find the sum of squares of a numeric vector"
]
sum-squares: function [
"Returns the sum of squares of all values in a block"
values [any-list! vector!]
][
result: 0
foreach value values [result: value * value + result]
result
]
print sum-squares []
print sum-squares [1 2 0.5]
You may also check:How to resolve the algorithm Range expansion step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Literals/String step by step in the Forth programming language
You may also check:How to resolve the algorithm String interpolation (included) step by step in the Delphi programming language
You may also check:How to resolve the algorithm Attractive numbers step by step in the LLVM programming language
You may also check:How to resolve the algorithm Count in factors step by step in the Run BASIC programming language