1.3 Because of round-off errors, it is customary to specify the number of decimal places that
should be included in the output and round up accordingly. Otherwise, numbers come out
looking strange. We assume error checks have already been performed; the routine
SeparateO is left to the reader. Code is shown in Fig. 1.1.
1.4 The general way to do this is to write a procedure with heading
void ProcessFile( const char *FileName );
which opens FileName,O does whatever processing is needed, and then closes it. If a line of
the form
#include SomeFile
is detected, then the call
ProcessFile( SomeFile );
is made recursively. Self-referential includes can be detected by keeping a list of files for
which a call to ProcessFileO has not yet terminated, and checking this list before making a
new call to ProcessFile.O
1.5 (a) The proof is by induction. The theorem is clearly true for 0 < XO ≤ 1, since it is true for
XO = 1, and for XO < 1, log XO is negative. It is also easy to see that the theorem holds for
1 < XO ≤ 2, since it is true for XO = 2, and for XO < 2, log XO is at most 1. Suppose the theorem
is true for pO < XO ≤ 2pO (where pO is a positive integer), and consider any 2pO < YO ≤ 4pO
(pO ≥ 1). Then log YO = 1 + log (YO / 2) < 1 + YO / 2 < YO / 2 + YO / 2 ≤ YO, where the first inequality
follows by the inductive hypothesis.
(b) Let 2XO
= AO. Then AOBO
= (2XO
)
BO
= 2XBO
. Thus log AOBO
= XBO. Since XO = log AO, the
theorem is proved.
1.6 (a) The sum is 4/3 and follows directly from the formula.
(b) SO =
4
_1_ +
42
__2_ +
43
__3_ +
. . .
. 4SO = 1+
4
_2_ +
42
__3_ +
. . .
. Subtracting the first equation from
the second gives 3SO = 1 +
4
_1_ +
42
__2_ +
. . .
. By part (a), 3SO = 4/ 3 so SO = 4/ 9.
(c) SO =
4
_1_ +
42
__4_ +
43
__9_ +
. . .
. 4SO = 1 +
4
_4_ +
42
__9_ +
43
_1_6_ +
. . .
. Subtracting the first equation
from the second gives 3SO = 1+
4
_3_ +
42
__5_ +
43
__7_ +
. . .
. Rewriting, we get
3SO = 2
iO=0
Σ
∞
4iO
__i_ +
iO=0
Σ
∞
4iO
__1_. Thus 3SO = 2(4/ 9) + 4/ 3 = 20/ 9. Thus SO = 20/ 27.
(d) Let SNO
=
iO=0
Σ
∞
4iO
i
ONO ___. Follow the same method as in parts (a) - (c) to obtain a formula for SNO
in terms of SNO−1, SNO−2, ..., SO0 and solve the recurrence. Solving the recurrence is very
difficult.
-1-
课后答案网 ww w.khdaw.com
若侵犯了您的版权利益,敬请来信通知我们! ℡ www.khdaw.com
khdaw.
com
khdaw.
com______________________________________________________________________________________________________________________________________________________________
double RoundUp( double N, int DecPlaces )
{
int i;
double AmountToAdd = 0.5;
for( i = 0; i < DecPlaces; i++ )
AmountToAdd /= 10;
return N + AmountToAdd;
}
void PrintFractionPart( double FractionPart, int DecPlaces )
{
int i, Adigit;
for( i = 0; i < DecPlaces; i++ )
{
FractionPart *= 10;
ADigit = IntPart( FractionPart );
PrintDigit( Adigit );
FractionPart = DecPart( FractionPart );
}
}
void PrintReal( double N, int DecPlaces )
{
int IntegerPart;
double FractionPart;
if( N < 0 )
{
putchar(’-’);
N = -N;
}
N = RoundUp( N, DecPlaces );
IntegerPart = IntPart( N ); FractionPart = DecPart( N );
PrintOut( IntegerPart ); /* Using routine in text */
if( DecPlaces > 0 )
putchar(’.’);
PrintFractionPart( FractionPart, DecPlaces );
}
Fig. 1.1. ______________________________________________________________________________________________________________________________________________________________
1.7
iO=OINO/ 2OK Σ
N
i
_1_ =
iO=1
Σ
N
i
_1_ −
iO=1
Σ
OINO/ 2 − 1OK
i
_1_ ∼∼ ln NO − ln NO/ 2 ∼∼ ln 2.
-2-
课后答案网 ww w.khdaw.com
若侵犯了您的版权利益,敬请来信通知我们! ℡ www.khdaw.com
khdaw.
com
khdaw.
com1.8 24
= 16 ≡ 1 (modO 5). (24
)
25
≡ 125
(modO 5). Thus 2100
≡ 1 (modO 5).
1.9 (a) Proof is by induction. The statement is clearly true for NO = 1 and NO = 2. Assume true
for NO = 1, 2, ..., kO. Then
iO=1
Σ
kO+1
FiO
=
iO=1
Σ
k
FiO
+FkO+1. By the induction hypothesis, the value of the
sum on the right is FkO+2 − 2 + FkO+1 = FkO+3 − 2, where the latter equality follows from the
definition of the Fibonacci numbers. This proves the claim for NO = kO + 1, and hence for all
NO.
(b) As in the text, the proof is by induction. Observe that φ + 1 = φ2
. This implies that
φ−1
+ φ−2
= 1. For NO = 1 and NO = 2, the statement is true. Assume the claim is true for
NO = 1, 2, ..., kO.
FkO+1 = FkO
+ FkO−1
by the definition and we can use the inductive hypothesis on the right-hand side, obtaining
FkO+1 < φkO
+ φkO−1
< φ−1
φkO+1
+ φ−2
φkO+1
FkO+1 < (φ−1
+ φ−2
)φkO+1
< φkO+1
and proving the theorem.
(c) See any of the advanced math references at the end of the chapter. The derivation
involves the use of generating functions.
1.10 (a)
iO=1
Σ
N
(2iO−1) = 2
iO=1
Σ
N
iO −
iO=1
Σ
N
1 = NO(NO+1) − NO = NO2
.
(b) The easiest way to prove this is by induction. The case NO = 1 is trivial. Otherwise,
iO=1
Σ
NO+1
i
O3
= (NO+1)
3
+
iO=1
Σ
N
i
O3
= (NO+1)
3
+ 4
NO2
(NO+1)
2 _________
= (NO+1)
2
O
H
A
I 4
NO2 ___ + (NO+1)O
J
A
K
= (NO+1)
2
O
H
A
I 4
NO2 ___ _+_ 4_N__O +__ 4_O
J
A
K
= 22
(NO+1)
2
(NO+2)
2 _____________
= O
H
A
I 2
_(_
N_O+_1_)
_(_N_O+__2_)
O
J
A
K
2
= O
H
A
I iO=1
Σ
NO+1
iO
J
A
K
黑皮书数据结构与算法c语言版第一章答案
最新推荐文章于 2025-07-22 21:20:35 发布