You are on page 1of 2

Howmanyel

ement
sdoest
hear
ray

i
nta[
5];

cont
ain?Whi
chi
sthef
ir
stel
ement
?Thel
ast
?

What
'swr
ongwi
tht
hisscr
apofcode?

i
nta[
5];

f
or(
i=1;
i<=5;
i=i
+1)

a[
i]=0;

Howmi
ghty
our
ewr
it
ethedi
ce-
rol
l
ingpr
ogr
am (
from t
henot
es,
chapt
er4,
p.2)wi
thoutar
ray
s?

Whati
sthedi
ff
erencebet
weenadef
ini
ngi
nst
anceandanext
ernal
decl
arat
ion?

Whatar
ethef
ouri
mpor
tantpar
tsofaf
unct
ion?Whi
cht
hreedoesacal
l
erneedt
oknow?

Tut
ori
alSect
ion

Hereisanot
hernest
ed-l
oopexample,
simi
l
artoexerci
se4ofassi
gnment1,andt
otut
ori
al3of
assi
gnment2.Thisonepri
ntsanaddi
ti
ontabl
eforsumsfr
om 1+1to10+10.

/
*pr
intanaddi
ti
ont
abl
efor1+1upt
o10+10*
/

#i
ncl
ude<st
dio.
h>

i
ntmai
n()

i
nti
,j
;

/
*pr
intheaderl
i
ne:
*/

pr
int
f(""
);

f
or(
j=1;
j<=10;
j=j
+1)
pr
int
f("%3d"
,j)
;

pr
int
f("
\n"
);

/
*pr
intt
abl
e:*
/

f
or(
i=1;
i<=10;
i=i
+1)

pr
int
f("
%2d"
,i)
;

f
or(
j=1;
j<=10;
j=j
+1)

pr
int
f("%3d"
,i+j
);

pr
int
f("
\n"
);

r
etur
n0;

Thef i
rstjl
ooppri
ntsthetop,headerrowofthetabl
e.(Theini
ti
alpri
ntf(
"");
istomakeitlineup
withtherowsbeneath,whichwil
lallbegi
nwithavalueofi.
)Then,theilooppri
ntstherestof
thetable,
onerowperv al
ueofi.Foreachv al
ueofi,
wepr i
ntthatvalue(onthelef
tedgeoft he
tabl
e),andthen

You might also like