How to calculate the dot product of two arrays in Pascal

1 Answer

0 votes
program DotProductProgram;

var
  arr1: array[0..4] of Integer = (1, 4, 8, 9, 6);
  arr2: array[0..4] of Integer = (0, 7, 1, 3, 40);
  i, dot: Integer;

begin
  dot := 0;

  for i := 0 to High(arr1) do
    dot := dot + arr1[i] * arr2[i];

  WriteLn('Dot product = ', dot);
end.



(*
run:

Dot product = 303

*)

 



answered 5 hours ago by avibootz
...