Skip to content

Commit a01efdb

Browse files
dion-adamkostis
andauthored
[Dana] gcd with unorthodox coding (#60)
--------- Co-authored-by: Kostis Sagonas <kostis@cs.ntua.gr>
1 parent 3d7cb49 commit a01efdb

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

dana/programs/gcd.dana

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
def main
2+
3+
def gcd is int: a b as int
4+
if b == 0: return: a
5+
else:
6+
begin
7+
var s is int
8+
s := gcd: b, a % b
9+
return: s
10+
end
11+
12+
var n1 n2 is int
13+
(* just messing around *) var d is int
14+
15+
writeString: "Give me two positive integers: \n"
16+
n1 := readInteger()
17+
n2 := readInteger()
18+
19+
# Making sure numbers are non-negative
20+
21+
if n1 < 0: n1 := -n1
22+
if not n2 >= 0: n2 := -n2
23+
d := gcd(n1, n2)
24+
writeString: "\nTheir GCD is: "
25+
writeInteger: d
26+
writeString: "\n"

0 commit comments

Comments
 (0)