Você está na página 1de 2

Thesubt

leandnott
hei
ntendedr
eci
pient
s

Gj
j
gand

We

We

Yj
fjksi
togchj
uty
ugy
yhh

Gj
iGTy
u

Gui
nguj

Gi
ojui
k

Tuj
hko

Hogi
ioj
hui
kj
hu

Hui
hi

Too

Hoo

Thesubt
lel
evel
of

Iwi
l
l

Thesubt
le

assignment(exer
cise3),you'
reaskedtocreateasimplefuncti
ontocomputet hesquar
esof
numbers.Sometimes,rat
herthanwr i
ti
ngaf unct
ionwhichwill
computeav al
ueeacht i
meit'
s
cal
l
ed, i
t'
susefult
obuildanarraycontai
ningallt
hev al
ueswemi ghtneed.Hereisaprogr
am
whichdeclar
esanar r
ay,t
henf i
ll
sitwit
hthesquar esofthenumbersfrom 1to10:

#i
ncl
ude<st
dio.
h>
i
ntmai
n()

i
nti
;

i
ntsquar
es[
11]
; /
*[0.
.10]
;[0]i
gnor
ed*
/

/
*fi
l
lar
ray
:*/

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

squar
es[
i]=i
*i;

/
*pr
intt
abl
e:*
/

pr
int
f("
n\t
squar
e\n"
);

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

pr
int
f("
%d\
t%d\
n",
i,squar
es[
i]
);

r
etur
n0;

There'sonesli
ghttr
ickinthedecl
arat
ionoft hesquar
esarray.Remembert hatar
raysinCare
basedat0.Soi fwewant edanarr
aytohol dthesquaresof10number s,andifwedeclaredi
tas
i
ntsquar es[
10];
thearray'
s10elementswoul drangefr
om squares[0]tosquares[
9].This
program wantstouseelementsfrom squares[
1]tosquar
es[10],soitsimplydecl
aresthearr
ay
ashav ingsi
ze11,fi
ggj j
gand

Hj
on

Guj
j
j

Gj
i
vj

Ggj
kvogj
wast
est
he0t
hel
ement
.

Você também pode gostar