Skip to content

Commit 6f3c154

Browse files
nicholas-aggkostis
andauthored
[Dana] Add Dot Product (#56)
* Add Dot Product program * Fix indentation of dot_product.dana --------- Co-authored-by: Kostis Sagonas <kostis@cs.ntua.gr>
1 parent 61a89ff commit 6f3c154

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

dana/programs/dot_product.dana

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
def main
2+
begin
3+
def dot_product is int : n as int, vector1 as int [], vector2 as int []
4+
begin
5+
var product i is int
6+
product := 0
7+
i := 0
8+
loop:
9+
begin
10+
if i == n : begin break end
11+
product := product + vector1[i]*vector2[i]
12+
i := i + 1
13+
end
14+
return : product
15+
end
16+
17+
var ex_vector1 ex_vector2 is int[4]
18+
19+
ex_vector1[0] := 2
20+
ex_vector1[1] := 4
21+
ex_vector1[2] := 6
22+
ex_vector1[3] := 8
23+
24+
ex_vector2[0] := 1
25+
ex_vector2[1] := 3
26+
ex_vector2[2] := 5
27+
ex_vector2[3] := 7
28+
29+
var result is int
30+
result := dot_product : 4, ex_vector1, ex_vector2
31+
writeString : "The dot product of the two vectors is: "
32+
writeInteger : result
33+
writeChar : '\n'
34+
end

dana/programs/dot_product.result

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The dot product of the two vectors is: 100

0 commit comments

Comments
 (0)