Professional Documents
Culture Documents
c_a><z-_
;*:
,l
,/
Write a prograrn !o prirrt this trianglc: by tak|ng the linc nunrbcr N as an iirput.
,/'i
tl
Sample Output:
'I
t,
N:10
*
l:
l
'
.
"'r.
r
I
'
It
;
*****
*******
Al+*J**a*tt
***t****r*r**
***************
*****************
**i***tttt*t**a*a0*
,, !i ' :
'lr.
l.;,t.. r
I
'n
:
3.
Wlaat are the two dil'ferent kinds of division that tltc /, operator can
'\
circumstanccs ctocs it pcrform
each?'
do?,ui{91
ri
4. What are the clcfinitions of the "Boolean" valucs true wQfu/sc .in t? ' I
5. Name tltrcc uses lor the senricoton in C.
using a while loop, bc for the cxantplc
Sr,afunurwould the equivalent co<le,
z
'
/
I
for(i=0;i<10;i=i+1)
printf ( "i is td\n', i);
7.
' '
-t'-
; '
is
Reatl a positivc integer valuc, and compute the firllowing scqucnce-' llthcinlm-ber
ptoccss''
Rcpcatlhis
euen, l,afr'" it( ttividc it by 2 ); if il': odcl, nrqllpgil:9!&99-L'
until the value is l. printing oufdffivalueJtin;liy dffit out how many of
operations you
I
i!!
t!9W
performed.
, ,t
, i
,-. value is
'|lext
I,lext, valrre is
Next value is
'tle1!:r va)ue
Nexfi ivalue
njn*t'l value
i'iltext value
.l't'Oxtrtl
[ior{ti,l'va1ue is
Noxb*value is
il:r",i!T,r
lr'
i
ri
,l
l: I
":,,
l'l,i
lill
ii
ir
't
1l
32
:6
13
40
i
,rllrlirlf\li
iir 'll;ri'i
''"it''
il',',
l4
is 1l
34
is
is
is
value is
',,.
,r',
Do'a I nrQ
ri
,]
il.
.:f i
:;
,
*
I
i
J{o
.l.l
ti
'l'
,t,
rli
"i,
t/
:,1
'|:
'!t
'l
,i
it
t.
,?'
,!
conlainirtg the
rvord :
E i:ror
in
exit( 0 );
and perfornr
\,
(:l he bnsc will bc
Write 0 progranr rvhich will read n dccimnl integcr valuc thcn a busc
lcss than or cqual to l0_.), rhen print its value ofrhat
basc.
rttiffil
riililll'
liil
'
t:
: < a?
\\'hal. is t!tc
"water"?
//,n,9.
rc-Under rvhat conctitions will this code print
'r/
if('I'<
I,
3.)
Jrrintf("ice\h");
< 2l?-l
el se i f (1'
)t.
lse
-a'
',
i''rt. x : 3,'
i-f (x)
olse
prirrtf 1"yes\nd);
Fri,,r t ("no\n"l ;
.:
,.1
.t
12.
(trick question)
irrt
.l
ror(l * 0; i < 3; i = i + ii
['ri
f
f ("a\n"
nt-
);
,r i trt f ("b\n" ) ;
t.,
.l
1xsg1n6
'ti'
!-
int nrain0
i,'ll
'r
int i
printf ("statemerrt 1\n") i
printf ( "slatement 2\n"); + 1)
i6s1i = O; i < 10; i: i
:'l
tl
, ll
i ;r
,":i
,l;l
'
;.i
' ,i'i
,''i
*i nclucle tut.liC:.!>
l'
.. ,i
l:
1;r'i
r
printf ("statement 4\nr');
li
I
l.iprintr(''st-atel0ent5\tl'')'',i;'..
i:
't
,!!
,l
lr,
'i,,
,
I
,"
''t
I'
li
l,i
.i
,"
!1"
retuJtr 0;
:
'l'lris prograllr d(\csli't clo anyfhing useful; ifs just supposccl ro sholv /ou ltorv conlrol 'flov'
fl:e cilter' cxcept wht-n a colistructioll sticlt
rvArl:s--horv stitte Itlcnts arc cxccuted oneattci
autl
tlrat certain siate*lc'ts ge. cxcci'rteci o'cr
as tle f or: rooli alters trre lrorv b1, ananging
nt r lirnction'
ti',,'-';;i"s;;;;. ;;.ii titprt starcineirt is iust a ca:i to the pr i
"ilb.
il
.l'rlllll
I
iL
P.rop ?
l,',
1l
iir
i
:1
a
I
,rl
No*'clclcte
1l:r.:
Iiow
dcies
i ncl rrcle (s
Lcl
j o. h>
int m;jn o
{
inl- i, );
print f ( "start of
pr:ogratn\rt" ) ;
f6s(i" = 0; i < 3; i = i +
1)
(t!
printf("end of Program\n")t
'''
return 0;
'
'
)rl
-I.hisprogr:rmdbcsntclomirchuscrul,eitlrr':r;ir,sjustsrtpposcclto-s!tou,ylrulrt,rv.ltlops
l, atitl ?,
*,",rt ani iruq. loops-can be nesterl. The outcr hlop runs i tlrrougrh.tlr0 virlucs.0,
' each of tlrcsc tlrrec values of i. (thnt is, durirtg cflch of the tlrrcc tiips through thc
an.lf,,r.
4',
outer loop) Llre ilrrcr loop runs, stepping the variablc i throtrgh 5 r'alttc's,0 to
with
Irr,p.'rinrcnt rvii5 clianging rhc li,liti (initi:rlly 3 antl 5) oll thc tsio loolrs. Iixllcrinrcnt
j
intcrchangipg thc trvo iottps. ttrat is, by having the outcr loop nraniprrlntc f hc ynriablg
to
the
and the inn.itnop nnanipulate the variable i. Finnlty, comparc this prograrn
,lriangle-printing prograrn of prolf3m 2 and its ans\\'er as ltanded out lllii \r'cck'
;
15.
inclrrrle <;t.tlio.h;'
ll
inL
{
main
ittl cl;rl',
f
ot
*.
1)
ir(i
.day)
'
== t)
{
*
li
,]
printf (rr\P");
i
I
',
returil 0;
!,
1 r
p.1..'.q
'l /)q8
..8
.r;,.
shoulcl bc an approxinration
g":iY^l'::;*.i
ritr'ht gucss)
Thc rcsult (rs y.u migltt
runo.
1il13"'i n g" s
;:'f;
if
(daY
of
thr-.1
I
cs
first tlrrcc
'
c n' I nvi
g'
c'[
c)
;i'].r ("rirstf');
!i
prosrlnl
thc inner port of the
writlng
of
way
c. Herc is nnbthcr
rrr day);
day of Cltrli-masr ;
tcl
tlr':
("On
orintf
to me\n")
,,r i,rrt r (',my
ir tttur'
i f (day
tru."iou"'guu"
;t"'ltf
;ttt']tf
if(daY >= 1)
(
i f (day == 1) Prlntf a"A..:']
");--'
("And'
Printf
;i;.'
a
in Pcar trF,e;\n!'
r!
Ptittr(iPartr:i'Jg':
r
\l^.'
thcrc afc no el se's
rvor;ks' Noticc tlrat
it
horv
out
rncthod and {igu:c
StudY this altcrnatc
rlt
lq
r's'
i
.:
the
betweetr
)
ffi
^['Jl#1;*;* jru:;',ll','"llEi;lTi;11;iy*h*;il1,f
"-,'li:'.lu^:"1,,i,1:::11:.-"[:],['l]il,t'rT;T"r*
,ilntl',i,:l
hil'Jdf #;J:j;3fl
'
:illh;';;n,.
:l'.i'il'n'i'i'i''o'f i"t
l;'ffi'""i',1?3;li'X,"1ffi f, fi
,
i-:. .,\,\
.r^^r
, *'ii,:ii::il:'ll;,:".',1,i::':'i;fiHlfi'liyi.li
,,,''
l rro*'i."ril;;k;i";t*".r
modirica,ion-of lr*.r.ii.
le
lu*
lli :1;il';il'#i
.";;;;'
,
,r:,
ii.
';l;'i;;;''n
.//'
I
L
this:
<-rdd
j s et.ren
i s oclc-l
(llint:
usc tltc
t o,)eril!n'\
,rlLL
,,'ill,r
,;rli,,
P:rrt,..d rrf.li
1l
-*4F
-.:d--"-""'-'''
#1
rl
1
(
\
.l.'
\/
:r-\
1 -p-,
cquatiott
rc
.t,
quantity;t;;;i; i"r,
dirti.r:
.c.-
a''2
tr6
c=!
t2
-3
6
-4
<t
I
I
int al51;
?"tri"= 1; i <-:); i - i + 1)
ni.*" en a dtlfinitrg
25s \r/rrar is trrc dir[li,]""
parls
26. $,hat are rtre to*r irnpbrrant
,t'"*{r:T'"oclc
I
rl
in$t(r,rca-a'd
"i;';;;d;nz
wtri"t
an csrct'nur tryc'rtu'tttitull'"'
thr,ce clocl
of inu' (write it
to sunr the clcments of an array
*trttt tlte arrav
;il;ut"l,-it
?:. 6}t
as
necd to
"
iluttt
a'f,riiiion;il'you
,,1rl
thc
(chapter 5.' scciion 5'll p I ) on
ltnction
t
)
rnultbytrvo
tltc
call
to
loop
2g. write c
iunction nnd llte l]it tovi'o t
extra creclit, tg*piit
\f' w'\rr"
10. rl;or
l-l\,,'
nunrt ers 1lltu]1t)grs
I
I
'
lunctiorr pcr filc'
onc
files'
source
tw:o
as
function
tnc nurrrir;1s I -10:
,i r.,ua,:res
1f
(y'write,, on,,u,o
yJ"illi"
,'iTilt;ru;;il ,;illi
i,
10
81
100
(int'
in,t n)
' . rr - -r--d^t^r'cn' n tinres' (Remenr iher tltatidc is the printf
is sttl;posc'tl to print the characle(
voi<i prinLni:hars
c,fr,,,
rvhich
Foi cxanrplc, thc call print'nch'\rs
format to usc f,,, p,i,.,ii,,f "iarucrers.)
i'
.Pann.5.nf.8
('x''
'l
I
'i\
,j
:;,
I
would print 5 ,,'s. [Jse this lunction to rewritc the triangle-printing program of
assignmcttl Program 4,
;
3L-Writc a luncli6n to contpute the lactorial of a nutttbcr. itlttl trsc it to print the factorials
-" of t5e nunrbers l-7. (lrxira credit: print the factorials of tltc ttuntbcrs l-10.)
rire rotto*ing gradcs ror the six examinatllT tak'n n a c
,,'
i;|**""i,il*ilf
I
I
NsE-._
AJams
lrii,lliil'
5)
45
ffiL-
40
Hamilton
90
60
55
--'
)
0.'
r!iitiil
ilit
ir
55
Ilrorvn
i,liiliitllllrlri
1,1
90
40
-41
Prince
-Brs!'3lg!--_
'l'hotnas
- O
3k-Cenirntc
Z ;;;ir.r
\
60
(l rc ft rI
lorvi
tt11
t;
232
34s43
4567654
567398765
(178901 A987 (,
7S90l23llOes7
i.
'
do'/
,l
,.
t,
Why nrust 1l,c varia[le ttsed to hold getchar's return valuc bc type i"l?
38. \\'hal is thc dillcrcnce bctu'een tlrc prefix and postfix fornts of the + r" '!opcrator?
39. (trick qucstion) What would the expression
-17.
i = i++
dr?
i
I
;
C?
'
40. Whal is the tlefirrition of a string in
411,. Writc a progranl to read I- tglisli text to ettd-of-ttata (typc # to irtdicr,tc cnd of data),
ancl print i, counr of word lengths, i e. tFtotal ntrmbcr of u'ords oI lcngth I which
rt
*uluerrye ol'ulpltuh<'tic
,i, occurrcd, tfic nurrtbcr o f length 2, and so on. DeJinc o onl to I,re a
letlcrs.
'
,;iili,i
Pnp^.6 nf.P
./
.re .ts
C)
l'o^oo C)
IengLtr 1 :
J engl-h 2 :
I.t:r: _rt ir .3 :
lerr'lLlr 4 '
Ierir;Llr 3:
C)
\\5c-tc,L*t"+,*lc-n
10 occurrences
19 occurrences
127 orcurrences
0 occrlrrences
I'B occurrences
L)
'
iillll
,i,ililli
,lllrliilil
,illlillil
,l,'I
a rtr'rl;
rcadsl"il';ii1Tt*,1':.0^:ll1lly"::';:Tl[l'.i]:it'""il'n.
trrat rcass
prosrom lllat
.cncl h<lrn lcft nnd
writo o progrom
Writo
43. ""J
iti"e is.pnlinclrome if it cnrr bc t pnriqdromq'
orl.*.ln
string is n 1ta!iwlr,,-u
Igrrorc
rgnorc
n""" arc
and A,.r,..repoiina,o*e.
$,'lxlflilli,
,,
r'--"li'l
r :ilLr#,ili'#Hr:Tfilirl
{ ,: lli:h,llll:i'"'"
r
'l
#;ilffii;;i''
Fil;il;;il;;;nd
""am
|:r
;;;;il;;li,"*r.,.'iirencountersthcencloftlrcfile.:.
Typical oulpttt might
rl
bc
Reacl
a
file
of
Enqi i sh
text
ancl
pr i nt-
it
out-
one
ctc.
:'i
,rl
li
it'
will the letllne lttttction front section tr'3 of thc niitcs clo
'i:rlt'"tls
successivccallstor;':tr:harreturntltcfourvalucs "a"'b"'c":rntl
to occ\lf',tllat is' fi'rr :r
gcr
t. i
i:
"linc" sottrcltorv not to be terminatetl lry tn?
.
a
($iesunrably
string
a
atoi, wltich takcs
46. T'he stlnclartl library contailts u fun.tion.
rctttt'n
would
l'br exantplc, atoi t " 1'? I
string ol digits) anrl cottverts it to nn ini.g"t.
t
,I
il
li
write
some
divisic.,n tnrncates, so^1'ou'll ltave to dcclere
double.
t'lr
ll,
r:lreC k
;'l
.:;
Lt'..,1tl
che c k
49.00
dePosit
$r
7:oI
'rlt,t'
'",
.ijr,
lJ;11 f .nl'R
il,i
too.oo
:
balance: 8 /.66
ba lance': 3B:66
balance: 45.67
ba 1. ance
-,t
progranl tekc thc word ':itreck"' or '
the
havc
you
might
airout'5ow
Extra creclit: l.5ir*
tinc (seiaralcd bv rvlritc'1""'
,.
'i,:.'gr"
i,
charictcr at a time"ahd print'cacl'righaraltcr
4g. write a progrnm to reatl its input, one
lzrJ
",,;;;;;il;'t;i;;,
flUil',fi,:tlT?lJ:ilii,o
'l i'l I fr r- .L^
'
lr';o
, ,
-^.,^--:^- rrrrilp
fiinction
pri*ic:rcrr rinc,backwirds'l
'
i
(')
/r.\
1 g-trunr-vL"J
...
e".le
'
t.
rcturn a'ytlring
ll