Problem: Print a number (an integer)
Recursive algorithm:
Pseudocode:
procedure PrintNum (N : in integer) is begin print the number N DIV 10; print the digit N MOD 10 end PrintNum;
Stopping condition added
procedure PrintNum (N : in integer) is begin if N < 10 then print the digit N else print the number N DIV 10; print the digit N MOD 10 end if; end;
procedure PrintNum (N : integer) is begin if N < 10 then put(N,WIDTH=>1) else PrintNum (N DIV 10); put ((N MOD 10), WIDTH=>1) end if; end;