Programming and Graphics

(Kiana) #1

8 Introduction to C++ Programming and Graphics


[


...[(bk2+bk− 1 )2+bk− 3 )2+...+b 1

]


2+b 0 (16)

+

[


...[(b−l^0 .5+b−l+1)0.5+b−l+2)0.5+...+b− 1

]


0. 5 ,


and then carrying out the computations according to Horner’s algorithm: First,
we set


ak=bk, (17)

and compute the sequence


ak− 1 =2ak+bk− 1 ,
...,
ai =2ai+1+bi,
..., (18)
a 0 =2a 1 +b 0.

Second, we set


c−l=b−l, (19)

and compute the sequence


c−l+1 =0. 5 c−l+b−l+1,
...,
ci =0. 5 ci− 1 +bi,
...,
c− 1 =0. 5 c− 2 +b− 1 , (20)
c 0 =0. 5 c− 1.

The required number is equal toa 0 +c 0. Computing the decimal number in
this manner requires a reduced number ofk+lmultiplications, and an equal
number of additions. When the cost of addition is much less than the cost
of multiplications, Horner’s algorithm reduces the execution time nearly by a
factor of two.


Character representation


Characters include the lower- and upper-case letters of the English
alphabet, a–z and A–Z, numbers, special symbols such as % and<, and control
characters used to convey messages to printers and storage devices. Comput-
ers represent and store characters as encoded binary strings corresponding to
integers.

Free download pdf