37 lines
772 B
Nim
37 lines
772 B
Nim
proc plus(x, y: int): int = x + y
|
|
proc multi(x, y: int): int = x * y
|
|
|
|
let a = 2
|
|
let b = 3
|
|
let c = 4
|
|
|
|
echo a.plus(b) == plus(a, b) # True
|
|
echo c.multi(a) == multi(c, a) # True
|
|
|
|
# Verketteter Aufruf
|
|
echo a.plus(b).multi(c) # (2 + 3) * 4 = 20
|
|
|
|
# Alternativ
|
|
echo multi((a.plus(b)), c) # (2 + 3) * 4 = 20
|
|
|
|
|
|
proc findBiggest(a: seq[int]): int =
|
|
# result = 0
|
|
for number in a:
|
|
if number > result:
|
|
result = number
|
|
# Ende der proc
|
|
|
|
let d = @[3, -5, 11, 33, 7, -15]
|
|
echo findBiggest(d)
|
|
|
|
proc toString(x: int): string =
|
|
result = if x < 0: "negativ"
|
|
elif x > 0: "positiv"
|
|
else: "Null"
|
|
|
|
proc toString(x: bool): string =
|
|
result = if x: "ja" else: " ein"
|
|
|
|
echo toString(13) # "positiv"
|
|
echo toString(true) # "ja" |