How to resolve the algorithm Dot product step by step in the SNOBOL4 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Dot product step by step in the SNOBOL4 programming language

Table of Contents

Problem Statement

Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors. If possible, make the vectors of arbitrary length.

As an example, compute the dot product of the vectors:

If implementing the dot product of two vectors directly:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Dot product step by step in the SNOBOL4 programming language

Source code in the snobol4 programming language

        define("dotp(a,b)sum,i")        :(dotp_end)
dotp    i = 1; sum = 0      
loop    sum = sum + (a * b)
        i = i + 1 ?a :s(loop)
        dotp = sum      :(return)
dotp_end

        a = array(3); a<1> = 1; a<2> = 3; a<3> = -5; 
        b = array(3); b<1> = 4; b<2> = -2; b<3> = -1;
        output = dotp(a,b)
end

  

You may also check:How to resolve the algorithm Two's complement step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm 100 prisoners step by step in the Forth programming language
You may also check:How to resolve the algorithm Count in factors step by step in the Action! programming language
You may also check:How to resolve the algorithm Simple turtle graphics step by step in the Action! programming language
You may also check:How to resolve the algorithm Function definition step by step in the Pop11 programming language