\magnification1200
\def\\{\char92}
\font\cc=courier at 10pt

\newdimen\hba\hba=\hsize\advance\hba by -60pt

\long\def\hide{\par\setbox0=\vtop\bgroup}
\def\endhide{\egroup\relax%
\par\vrule width 80pt depth .1pt height0pt\par\vskip4pt%
\noindent\unvbox0}
\def\leaderfill{\leaders\hbox to .5em{\hss.\hss}\hfil}

\def\ap{\medskip\noindent\hbox to \hsize{\leaderfill}
\par\medskip}

%\long\def\hide#1\endhide{}

\def\la{\char60}
\def\ra{\char62}
\def\lb{\char123 }
\def\rb{ \char125}
\def\vr{\char124}
\def\frac#1#2{{{\cc{#1}}\over{\cc{#2}}}}
\newcount\pn\pn=1
\newif\iftest
\testtrue
\testfalse
\def\newp{%
\setbox0=\vbox\bgroup
\ifnum\pn>1 \iftest\vfill\eject\else\vskip20pt\fi\fi%
\noindent{\bf \number\pn.}\ \global\advance\pn by1%
}
\def\Newp{%
\setbox0=\vbox\bgroup\vskip-20pt
\ifnum\pn>1 \iftest\vfill\eject\else\vskip20pt\fi\fi%
\noindent{\bf \number\pn.}\ \global\advance\pn by1%
}
\def\endp{\egroup\box0\vfill\eject}


\def\code{\vtop\bgroup\bgroup\obeylines\cc\ccode}
\def\ccode#1{#1\egroup\egroup}
\def\tabit{\hskip\parindent}

\newdimen\AA\AA=9pt
\def\boxit#1{\vbox{\hrule\hbox{\vrule\kern3pt
	\vbox{\kern3pt\hbox{\hskip\AA\hbox to 0pt{\hss#1\hss}\hskip\AA%
\vrule width 0pt height10ptdepth4pt}\kern3pt}\kern3pt}\hrule}}

\def\lboxit#1{\vbox{\hrule\hbox{\vrule\kern3pt
	\vbox{\kern3pt\hbox{\hskip\AA\hbox to 0pt{\hss#1\hss}\hskip\AA%
\vrule width 0pt height10ptdepth4pt}\kern3pt}\kern3pt\vrule}\hrule}}

\centerline{\bf Math 211 Midterm}
\centerline{\bf March 27, 2002}
\centerline{Professor L.~Taylor}
\medskip
\noindent{\bf Name:\ }$\underline{\hskip4in}$
\bigskip

\newp
The statements below represent part of a long program. The {\cc while} loop was
intended to execute some bit of code three times 
(with {\cc index} being $0$, $\frac13$ and,
$\frac23$) and then move on. 
Assume that the code in {\bf Some code} uses the value in {\cc index} but
does not change it.

Then in fact, the {\cc while} loop repeats many more than three times
and may very well be an infinite loop. Why?
\bigskip

\code{
\tabit$\vdots$
float index;
\tabit$\vdots$

index=0.0;
while(index!=1.0) \lb
\tabit\tabit {\bf Some Code}
\tabit\tabit index+=1.0/3.0;
\tabit\tabit\rb
}

\ap
The issue here is one of precision. {\cc index} is a floating point number so the
representation of {\cc 1.0/3.0} is not exact: think finite decimal $.3333$ say.
When we increment {\cc index} $3$ times it will be very close to $1.0$ but not
precisely equal so the test will remain true and the loop will continue.

It is possible that the loop will terminate eventually. Since there are only finitely
many possible real numbers which can be represented in our machine, we might eventually
luck into $1.0$ and the loop  would quit, but certainly not when we expect it.
\endp

\newp
The following {\cc for} loop prints a sequence of integers on a line.
Write those integers on the line below in the order in which they are 
printed. Assume {\cc ii}
has been declared already.
\medskip
\code{
for( ii=1; ii<=30; ii*=ii,ii++) \lb
\tabit\tabit printf("\%d ",ii);
\tabit\tabit\rb
}
\vskip20pt
\noindent Integers = $\underline{\hskip.6\hsize}$
\ap
First {\cc ii} is set to $1$ and the test condition is checked: since $1\leq 30$ the
test succeeds and we print a $1$.
Then we do the increment condition which is done in two steps: first we do {\cc ii*=ii}
which has the affect of replacing the value in {\cc ii} by the square of that value.
Next we increment the value in {\cc ii} by $1$.
In our initial case {\cc ii=1} so now it is $1^2+1=2$.
Then we check the test condition: since $2\leq 30$ the
test succeeds and we print a $2$.
The increment conditions replace the value in {\cc} by $2^2+1=5$.
Again we check the test condition: since $5\leq 30$ the
test succeeds and we print a $5$.
The increment conditions replace the value in {\cc} by $5^2+1=26$.
Again we check the test condition: since $26\leq 30$ the
test succeeds and we print a $26$.
The increment conditions replace the value in {\cc} by $(26)^2+1$ which is
bigger than $30$ so the for-loop quits.
\endp


\newp
Consider the following code for a function:
\bigskip
\code{
short strange(char cc) \lb
char  xx=4;

switch(cc)\lb
\tabit case 'a': xx+=3;
\tabit case 'b': xx\%=3; break;
\tabit case 'c': xx-=123;
\tabit default: xx=0;
\tabit\rb
return(xx);
\rb
}
\bigskip
What value is returned by {\cc strange('a')}?\hskip20pt$\underline{\hskip.5in}$
\bigskip
What value is returned by {\cc strange('c')}?\hskip20pt$\underline{\hskip.5in}$
\bigskip
Be sure to read the code carefully.
\ap
This is an exercise in being careful. When evaluating {\cc starnge('a')} we begin the
{\cc switch}-loop with {\cc case 'a':}, which adds $3$ to the value in {\cc xx}, xo {\cc xx} is
now $7$. Since there is no {\cc break;} we drop through and do the next line, which replaces
$7$ by its remainder when divided by $3$, so {\cc xx} is now $1$ and this is the value returned.

When evaluating {\cc starnge('c')} we begin the
{\cc switch}-loop with {\cc case 'c':} which subtracts $123$ from the present value in {\cc xx}.
Again we drop through so this value is replaced by $0$ and that is the value returned.
\endp


\Newp
You have just solved a linear second order differential equation using
the power series method. 
You have written your solution as $\displaystyle\sum_{n=0}^\infty a_n\>x^n$
and determined that the $a$'s are related by the recursive relation
$a_n=2*a_{n-1}-3*a_{n-2}$.
You have also determined that $a_0=1$ and $a_1=-3$.
You want to examine the other coefficients so you write a program to print out
the first few values.
I have written such a program for you {\sl except\/} you need to add some code
to fill in the values in the {\cc a}-array.
You are to add your code in the blank space between the line initializing 
{\cc aa[0]} and {\cc a[1]} and the {\cc for} loop doing the printing.
A second copy of my code is provided {\sl below} the horizontal line for
your scratch work so your final answer should be legible.
\bigskip
\setbox1=\vbox{
\code{
\#include \la stdio.h\ra
\#define\tabit MAX\tabit 30
\bigskip
main()\lb
short  ii;
short  a[MAX];
\medskip
a[0]=1; a[1]=-3;
\vskip 1true in
for(ii=0;ii<MAX;ii++) \lb
\tabit printf("a\_\%d = \%d\\n",ii,a[ii]);
\tabit\rb
\rb
}}
\copy1
\bigskip
\noindent$\underline{\hskip\hsize}$
\bigskip
\copy1
\global\footline{}
\endp
\ap
Add the following code after the initializations {\cc a[0]=1; a[1]=-3;}
and before the {\cc for}-loop doing the printing:

\code{
for(ii=2;ii<MAX;ii++) \lb
\tabit a[ii]=2*a[ii-1]-3*aa[ii-2];
\tabit\rb
}
\end