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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Sum of squares step by step in the REXX 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 REXX programming language

Source code in the rexx programming language

/*REXX program  sums  the squares of the numbers  in a (numeric)  vector of 15 numbers. */
numeric digits 100                               /*allow 100─digit numbers; default is 9*/
v= -100 9 8 7 6 0 3 4 5 2 1 .5 10 11 12          /*define a vector with fifteen numbers.*/
#=words(v)                                       /*obtain number of words in the V list.*/
$= 0                                             /*initialize the  sum  ($)  to zero.   */
       do k=1  for #                             /*process each number in the V vector. */
       $=$ + word(v,k)**2                        /*add a squared element to the ($) sum.*/
       end   /*k*/                               /* [↑]  if vector is empty, then sum=0.*/
                                                 /*stick a fork in it,  we're all done. */
say 'The sum of '      #      " squared elements for the  V  vector is: "   $

/*REXX program  sums  the squares of the numbers  in a (numeric)  vector of 15 numbers. */
numeric digits 100                               /*allow 100─digit numbers; default is 9*/
parse arg v                                      /*get optional numbers from the C.L.   */
if v=''  then v= -100 9 8 7 6 0 3 4 5 2 1 .5 10 11 12      /*Not specified?  Use default*/
#=words(v)                                                 /*obtain number of words in V*/
say 'The vector of '    #     " elements is: "   space(v)  /*display the vector numbers.*/
$= 0                                             /*initialize the  sum  ($)  to zero.   */
             do  until v=='';   parse var v x v  /*process each number in the V vector. */
             $=$ + x**2                          /*add a squared element to the ($) sum.*/
             end   /*until*/                     /* [↑]  if vector is empty, then sum=0.*/
say                                              /*stick a fork in it,  we're all done. */
say 'The sum of '       #     " squared elements for the  V  vector is: "      $

  

You may also check:How to resolve the algorithm Chat server step by step in the Ol programming language
You may also check:How to resolve the algorithm AKS test for primes step by step in the Delphi programming language
You may also check:How to resolve the algorithm Draw a sphere step by step in the SVG programming language
You may also check:How to resolve the algorithm Variable declaration reset step by step in the Python programming language
You may also check:How to resolve the algorithm Arbitrary-precision integers (included) step by step in the Sidef programming language