factorial 🦖🦖🦖🦖🦖🦖🦖🦖
This commit is contained in:
42
tests/programs/factorial.alpha
Normal file
42
tests/programs/factorial.alpha
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#include "std.alpha"
|
||||||
|
|
||||||
|
function entry: string2integer
|
||||||
|
function calc: integerXinteger2integer
|
||||||
|
|
||||||
|
calc(counter, result) := {
|
||||||
|
|
||||||
|
if ( counter = 0 ) then {
|
||||||
|
return result;
|
||||||
|
} else {
|
||||||
|
result := result * counter;
|
||||||
|
counter := counter - 1;
|
||||||
|
return calc(counter, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
entry (arg) := {
|
||||||
|
[integer: result; integer: userInput]
|
||||||
|
|
||||||
|
result := printC('E');
|
||||||
|
result := printC('n');
|
||||||
|
result := printC('t');
|
||||||
|
result := printC('e');
|
||||||
|
result := printC('r');
|
||||||
|
result := printC(' ');
|
||||||
|
result := printC('N');
|
||||||
|
result := printC('u');
|
||||||
|
result := printC('m');
|
||||||
|
result := printC('b');
|
||||||
|
result := printC('e');
|
||||||
|
result := printC('r');
|
||||||
|
result := printC(':');
|
||||||
|
result := printC(' ');
|
||||||
|
|
||||||
|
userInput := inI(1);
|
||||||
|
userInput := calc(userInput, 1);
|
||||||
|
result := printI(userInput);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Reference in New Issue
Block a user