Você está na página 1de 1

i

nthisassignment(exerci
se3),you'
reaskedtocreateasimplef
unctiontocomputethesquar
es
ofnumbers.Somet i
mes, rat
hert
hanwr i
ti
ngaf uncti
onwhichwil
lcomput eavalueeachti
meit
's
cal
led,
it'
susef ul
tobuil
danar r
aycontai
ningallt
hev al
ueswemi ghtneed.Hereisaprogr
am
whichdeclaresanarr
ay, t
henfi
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
arati
onoft hesquar
esarray.Remembert hatar
raysinCare
basedat0.Soi fwewant edanarr
ayt oholdthesquaresof10number 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,andwast est
he0t helement.

Você também pode gostar