Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int factorial(int n){
- int loop(int i, int& res){
- if (i > 0){
- res = res * i;
- loop(i - 1, res);
- }
- }
- int res = 1;
- loop(n, res);
- return res;
- }
- function factorial(n:i32): i32{
- function loop(i:i32, res:ref i32){
- if (i > 0){
- *res = *res * i;
- loop(i - 1, res);
- }
- }
- var res:i32 = 1;
- loop(n, &res);
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement