SHARE
TWEET

Untitled

tinyevil Dec 28th, 2018 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top