Advertisement
tinyevil

Untitled

Dec 28th, 2018
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.35 KB | None | 0 0
  1. int factorial(int n){
  2.     int loop(int i, int& res){
  3.         if (i > 0){
  4.             res = res * i;
  5.             loop(i - 1, res);
  6.         }
  7.     }
  8.     int res = 1;
  9.     loop(n, res);
  10.     return res;
  11. }
  12.  
  13. function factorial(n:i32): i32{
  14.     function loop(i:i32, res:ref i32){
  15.         if (i > 0){
  16.             *res = *res * i;
  17.             loop(i - 1, res);
  18.         }
  19.     }
  20.     var res:i32 = 1;
  21.     loop(n, &res);
  22.     return res;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement