How to resolve the algorithm Sum of squares step by step in the Groovy programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Sum of squares step by step in the Groovy 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 Groovy programming language
Source code in the groovy programming language
def array = 1..3
// square via multiplication
def sumSq = array.collect { it * it }.sum()
println sumSq
// square via exponentiation
sumSq = array.collect { it ** 2 }.sum()
println sumSq
You may also check:How to resolve the algorithm Range expansion step by step in the UNIX Shell programming language
You may also check:How to resolve the algorithm Sorting algorithms/Quicksort step by step in the BASIC programming language
You may also check:How to resolve the algorithm Canny edge detector step by step in the Julia programming language
You may also check:How to resolve the algorithm Kernighans large earthquake problem step by step in the Scala programming language
You may also check:How to resolve the algorithm Sorting algorithms/Selection sort step by step in the Crystal programming language