Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions dana/programs/dot_product.dana
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
def main
begin
def dot_product is int : n as int, vector1 as int [], vector2 as int []
begin
var product i is int
product := 0
i := 0
loop:
begin
if i == n : begin break end
product := product + vector1[i]*vector2[i]
i := i + 1
end
return : product
end

var ex_vector1 ex_vector2 is int[4]

ex_vector1[0] := 2
ex_vector1[1] := 4
ex_vector1[2] := 6
ex_vector1[3] := 8

ex_vector2[0] := 1
ex_vector2[1] := 3
ex_vector2[2] := 5
ex_vector2[3] := 7

var result is int
result := dot_product : 4, ex_vector1, ex_vector2
writeString : "The dot product of the two vectors is: "
writeInteger : result
writeChar : '\n'
end
1 change: 1 addition & 0 deletions dana/programs/dot_product.result
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The dot product of the two vectors is: 100