Advertisement
yoursunny

shijunxiao_test_02.ob

Mar 13th, 2016
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (*
  2. deep calls
  3. (c) 2013 yoursunny.com, CreativeCommons BY-NC 3.0, non-commercial use only *)
  4. MODULE module;
  5.  
  6. PROCEDURE writeln(s: ARRAY OF CHAR);
  7. BEGIN
  8.   WRITE(s);
  9.   WRITE(0AX);
  10. END writeln;
  11.  
  12. PROCEDURE printInt(n: INTEGER);
  13.   TYPE
  14.     c5 = ARRAY 5 OF CHAR;
  15.   VAR
  16.     s: c5;
  17.     i,c: INTEGER;
  18. BEGIN
  19.   IF (n >= 0) & (n <= 99999) THEN
  20.     COPY("00000",s);
  21.     i := 4;
  22.     WHILE 0 < n DO
  23.       c := ORD("0");
  24.       c := n MOD 10 + c;
  25.       s[i] := CHR(c);
  26.       n := n DIV 10;
  27.       i := 2 + i - 3;
  28.     END;
  29.     writeln(s);
  30.   ELSE
  31.     writeln("printInt: out of range");
  32.   END;
  33. END printInt;
  34.  
  35. PROCEDURE recursive(i: INTEGER);
  36. BEGIN
  37.   printInt(i);
  38.   IF i > 0 THEN
  39.     recursive(i - 1);
  40.     printInt(i);
  41.   END;
  42. END recursive;
  43.  
  44. BEGIN
  45.   (* http://cs553.site44.com/project3.html#comment-836429999 call depth is at most 100 *)
  46.   recursive(96);
  47. END module.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement