Skip to content

Commit b3c9bd1

Browse files
ntua-el21200kostis
andauthored
[Dana] Add factorial (#53)
* Add factorial * Update factorial.dana to homogenize its output with `factorial.dana`. --------- Co-authored-by: Kostis Sagonas <kostis@cs.ntua.gr>
1 parent 92100e3 commit b3c9bd1

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

dana/programs/factorial.dana

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def main
2+
3+
def fact is int: n as int
4+
if n <= 1: return: 1
5+
else: return: n*fact(n-1)
6+
7+
var input output is int
8+
input := readInteger()
9+
10+
output := fact(input)
11+
writeString: "The factorial of ";
12+
writeInteger: input
13+
writeString: " is "
14+
writeInteger: output
15+
writeString "\n"

0 commit comments

Comments
 (0)