Transcription of Answers to Selected Exercises - San Jose State University
{{id}} {{{paragraph}}}
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 (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.
The following answers are for C. Similar answers hold for Java and Ada. (1) The value of a variable is dynamic since it can change during execution. (2) The data type of a variable cannot change during execution; it is fixed during translation by its
Domain:
Source:
Link to this page:
Please notify us if you found a problem with this document:
{{id}} {{{paragraph}}}