¸ñÂ÷/Â÷·Ê
[¼Ö·ç¼Ç] ÇÁ·Î±×·¡¹Ö ¾ð¾î·Ð kenneth_c.louden 2ÆÇ ¼Ö·ç¼ÇÀÔ´Ï´Ù.
¸¹Àº µµ¿ò µÇ½Ã±æ!
º»¹®/³»¿ë
Programming Languages - Principles and Practice 2nd Edition
by Kenneth C. Louden Thomson Brooks/Cole 2002
Answers to Selected Exercises
? Copyright Kenneth C. Louden 2002
Chapter 1
1.2. (a)
function numdigits(x: integer): integer; var t,n: integer; begin n := 1; t := x; while t >= 10 do begin n := n + 1; t := t div 10; end; numdigits := n; end;
(c)
numdigits x = if x < 10 then 1 else numdigits(x / 10) + 1
(e)
function numdigits(x: Integer) return Integer is t: Integer := x; n: Integer := 1; begin while t >= 10 loop n := n + 1; t := t / 10; end loop; return n; end numdigits;
(g)
class NumDigits { public static int numdigits(int x) { int t = x, n = 1; while (t >= 10) { n++; t = t / 10; } return n; } }
Kenneth C. Louden
Programming Languages ? Principles and Practice 2nd Ed.
Answers - 2
1.5. (a) The remainder function, which we shall write here as % (some languages use rem or remainder), is defined by the integer equation a = (a / b) * b + a % b. The modu¡¦(»ý·«)