Practice Pseudocode Questions
Practice Pseudocode Questions
LEDBY:
UZAI
RSAYEED
Pr
act
iceQuest
ion–Pseudocode
1.Regisl
ivesi
nBrazi
landof
tentr
avel
stoUSA,Eur
opeandJapan.Hewantstobeabl
etoconver
t
Brazi
li
anReaisi
ntoUSdol
lar
s,Eur
opeaneur
osandJapaneseyen.Theconv
ersi
onf
ormul
ais:
cur
rencyv
alue=numberofReai
sXconv
ersi
onr
ate
Forexampl
e,i
fRegisi
sgoingt
oUSAandwantst
otake1000Reai
s(andt
heexchanger
atei
s0.
48)
thenhewoul
dinputUSA,
1000and0.
48andtheout
putwoul
dbe:480USdol
lar
s.
Wri
teanalgor
it
hm,usingpseudocode,whi
chinput
sthecountr
yheisvi
sit
ing,theexchanger
ate
andtheamounti
nBrazil
i
anReaisheistaki
ng.Theout
putwil
lbeval
uei
nforeigncurr
encyandthe
nameofthecur
rency
2.Aspartofanexperi
ment,aschoolmeasuredtheheight
s(inmetr
es)ofal
li
ts500student
s.
Writ
eanalgori
thm,usingpseudocode,whi
chinputstheheight
sofall500student
sandoutput
s
thehei
ghtoft
hetal
lestper
sonandt heshor
testper
soni nt
heschool
.
3.Ageogr
aphyclassdeci
detomeasur
edai
l
ytemper
atur
esandhour
sofsunshi
neperdayov
era
12monthper
iod(365days)
Writeanal
gori
thm,usi
ngpseudocode,whichi
nputst
het
emperaturesandhour
sofsunshi
nefor
all
365days,andfi
nall
youtput
stheaverage(mean)t
emper
atur
ef orthey
earandt
heaverage
(mean)numberofhoursperdayovert
hey ear
.
4.Asmallshopsell
s280di ff
erenti
tems.Eachitem i
sident
if
iedbya3–di gitcode.Al
li
temsthat
st
artwi
thazer o(0)ar
ecar ds,al
li
temsthatstar
twithaone( 1)aresweets,alli
temsthatst
art
wi
thatwo( 2)arestat
ioneryandalli
temsthatstar
twithathree(3)ar
etoy s.
Wri
teanalgor
it
hm,
usingpseudocode,whi
chinputst
he3–di
gitcodef
oral
l280i
temsand
out
putst
henumberofcar
ds,sweets,st
ati
oneryandtoy
s.
e-
mai
l
:uzai
r_say
eed@hot
mai
l.
com,
Cel
l#0345-
2317709Page1
COMPI
LEDBY:
UZAI
RSAYEED
5.Acompanyar ecar
ryingoutasur veybyobser vingtr
aff
icataroadj uncti
on.Eachti
meacar,
bus,l
orryorothervehicl
epassedbyt her oadjuncti
onitwasnot eddown.
10000vehicl
eswer ecounteddur i
ngthesurv ey.
Wri
teanalgori
thm,usingpseudocode, which:
inputsall10000responses
outputsthenumberofcar s,busesandl orr
iesthatpassedbythej uncti
onduri
ngthesur
vey
outputsthenumberofv ehicl
esthatwer en’
tcars,busesorlorr
iesdur i
ngthesurv
ey
6.Speedcamer asreadtheti
meav ehiclepassesapoint(A)ontheroadandthenreadsthet
ime
i
tpassesasecondpoint(B)onthesamer oad(
point
sAandBar e100metresapart)
.The
speedoft
hev ehi
clei
scalcul
atedusing:
100
Speed= (
metres/sec)
(
ti
meatpointB–t i
meatpoi ntA)
Themaxi mum all
owedspeedis100kil
omet resperhour.500vehi
clesweremonit
oredusingt
hese
camerasovera1hourper i
od.
Wr
it
eanalgorithm,usi
ngpseudocode, which:
i
nputst hest
arttimeandendt imeforthe500v ehi
clesthatwer
emonitored
cal
culatethespeedf oreachvehicl
eusingthef ormulaabove
out
put sthespeedf oreachvehi
cleandal soamessagei ft
hespeedexceeded100km/
hour
out
putt hehighestspeedofallthe500v ehi
clesmoni t
ored
e-
mai
l
:uzai
r_say
eed@hot
mai
l.
com,
Cel
l#0345-
2317709Page2
COMPI
LEDBY:
UZAI
RSAYEED
out
put
sthecostoft
het
icket
sandpr
int
sthet
icket
s
8.At owncont ai
ns5000houses.Eachhouseownermustpayt axbasedont heval
ueofthe
house.Housesov er$200000pay2%oft hei
rval
ueintax,housesover$100000pay1.5%of
thei
rvalueintaxandhousesover$50000pay1%oft hei
rvalueint
ax.Allot
herspaynotax.
Wr i
teanalgori
thm t
osolvet
heprobl
em usi
ngpseudocode.
9.Thef ol
l
owingfor
mul aisusedtocalcul
aten:n=x*x/ (
1–x)
Thev aluex=0i susedt ostopthealgori
thm.Thecal cul
ati
oni srepeatedusingvaluesofxunt
il
thevaluex=0i sinput.Thereisalsoaneedt ocheckf orer
rorcondi t
ions.Theval
uesofnandx
shoul
dbeout put.Wri
teanalgorit
hm toshowthisrepeatedcalcul
ationusingpseudocode.
10.
Wr i
teanalgor
it
hm usi
ngpseudocodewhicht
akestemperat
uresi
nputov
era100dayper
iod
(onceperday)andout
putthenumberofdayswhenthetemperat
urewasbel
ow20Candthe
numberofdayswhenthetemperat
urewas20Corabove.
11.
Wri
teanal
gor
it
hm usi
ngpseudocodewhi
ch:
i
nputsthetopspeedsof5000cars
out
putsthefast
estspeedandtheslowestspeed
out
putstheaveragespeedofal
lthe5000cars
(NOTE: Againsi
ncet heact
ualnumberofdataitemstobeinputisknownanyoneoft het hr
eeloop
structur
escouldbeused.Itisnecessar
ytosetv al
uesforthefast
est(usuall
ysetatzer
o)andt he
slowest(usuall
ysetatanunusuallyhi
ghv al
ue)sothateachinputcanbecompar ed.Everyti
mea
valueisinputwhich>thevaluest
oredinfast
estthenthi
sinputval
uereplacestheexi
sti
ngv al
uein
fastest;
andsimilar
lyforsl
owest)
.
12.
Ashopsell
sbooks,mapsandmagazi
nes.Eachi
tem i
sident
if
iedbyaunique4–digi
tcode.All
bookshaveacodestar
ti
ngwit
ha1,all
mapshav eacodestart
ingwit
ha2andallmagazines
haveacodebegi
nni
ngwi t
ha3.Thecode9999isusedtoendtheprogram.
Writ
eanalgor
ithm usi
ngpseudocodewhichi
nputthecodesforall
itemsinstockandoutput
sthe
numberofbooks,mapsandmagazi nei
nstock.I
ncludeanyv
alidat
ionchecksnecessar
y.
(NOTE:A4-di
gitcodeimpl
iesal
lbookshaveacodel yi
ngbet
ween1000and1999, al
lmapshavea
e-
mai
l
:uzai
r_say
eed@hot
mai
l.
com,
Cel
l#0345-
2317709Page3
COMPI
LEDBY:
UZAI
RSAYEED
codelyi
ngbetween2000and2999andal
lmagazi
nesacodel
yi
ngbet
ween3000and3999.
Anyt
hingout
sidet
hisr
angei
saner
ror
)
e-
mai
l
:uzai
r_say
eed@hot
mai
l.
com,
Cel
l#0345-
2317709Page4
COMPI
LEDBY:
UZAI
RSAYEED
13.
Thefol
lowingsect
ionofpseudocodei
nputs1000numbersandt
henout
put
showmanywer
e
negat
ive,howmanywer eposi
ti
veandhowmanywer ezero.
Locat
et he3err
orsandsuggestacorr
ectedpi
eceofcode.
1negat
ive=1: posi
ti
ve=1
2forx=0t o1000
3i
nputnumber
4i
fnumber<0t hennegat
ive=negati
ve+1
5i
fnumber>0t henposi
ti
ve=positi
ve+1
6endi
f
7endi
f
8next
9pri
ntnegati
ve,posi
ti
ve
14.
Thefol
lowi
ngsecti
onofpseudocodeinputsrainf
all
(incm)for500day
sandout
put
sthe
aver
agerai
nfal
landthehi
ghestrai
nfal
linput
.
Locat
ethe3error
sandsuggestacor r
ectedpieceofcode.
1highest=1000
2day s=1
3whi l
eday s>0
4inputr ai
nfall
5ifrainfal
l >highestthenhi
ghest=r
ainf
all
6endif
7total =total+rainfal
l
8day s=day s+1
9average=t otal/
500
10endwhi l
e
11pr i
ntav erage,highest
15.Thef oll
owingsecti
onofpseudocodei
nputsanumber ,n,
multi
pli
est
oget
her1x2x3x…….xn,
calculat
esinputnumber/
sum andoutputsresul
toft
hecalcul
ati
on.
Locatet he3err
orsandsuggestacorrect
edpieceofcode.
1inputn
2formul t=1t on
3sum =0
4sum =sum *mul t
5result=n/ sum
6next
7printresult
e-
mai
l
:uzai
r_say
eed@hot
mai
l.
com,
Cel
l#0345-
2317709Page5
COMPI
LEDBY:
UZAI
RSAYEED
16.
Acustomerwant stocompar epricesof1000i
temssoldintwosuper
mar
ket
s(pr
ice1and
pri
ce2)
.
Wri
teanalgor
ithm,usingpseudocodeoraf l
owchart
,whi
ch:
inputsthetwopr i
cesforall
1000i t
ems
outputshowmanyi temswer emoreexpensi
veinsupermar
ket1
outputshowmanyi temswer emoreexpensi
veinsupermar
ket2
outputsthelargestpri
cedif
ference
18.
Aschool has1500st udents.Itisconductingasurveyont heirmusi
cpr
efer
ences.Each
studentusesacomput erandi nputsthei
rnameandt henchoosesoneof5opti
ons:
• r ock( i
nputv al
ue1)
• soul (i
nputv alue2)
• pop( inputv alue3)
• j azz(inputv alue4)
• cl assical (i
nputv alue5)
Wri
teanal gorithm, usingpseudocodeoraf lowchar
t,which:
i nputst hechoi ceofal l1500st udents(val
ues1t o5)
out put sal l
thenamesoft hest udentswhochosecl assicalmusi
c
Out putst heper centagewhochoseeachopt i
on.
19.
Asur veyisbei ngcarriedoutwhi chinvolvesreadi ngandr ecor
dingsoundlev
elsnearabusy
roadjunction.Onceal l t
hedat aarecollected, t
heyar einputmanuall
yint
oacomput er
.Asound
levelof0deci bels(0dB)i sinputtoindicatet heendoft hedat
a.
Wri
teanal gori
thm, usingpseudocodeoraf lowchar t,which:
i nputsallthesoundl ev
els
af terasoundl evelof0isinput,output sthef oll
owing:
o aver agesoundl evel
o highestr ecordedsoundl evel.
e-
mai
l
:uzai
r_say
eed@hot
mai
l.
com,
Cel
l#0345-
2317709Page6
COMPI
LEDBY:
UZAI
RSAYEED
20.
5000number sarebei
nginputwhichshouldhav eeit
her1digit(e.
g.5)
,2di
git
s(e.
g.36)
,3
digi
ts(
e.g.149)or4digi
ts(e.
g.8567).
Wri
teanalgori
thm,usi
ngpseudocodeorflowchartonly,which
inputs5000number s
outputshowmanynumber shad1di gi
t,2digit
s,3digit
sand4di gi
ts
outputsthe%ofnumber sinputwhichwereout si
dether ange
22.
Asmal lshopusesbar codeswhi chrepr
esent5di git
s.Thel
astdi
giti
susedasacheckdi
git
.
Forexampl e:
a b c d e
0 1 2 3 4
Thecheckdi git(e)i
sf oundby :
mul tiplyingthef i
rstandt hi
rddi gi
ts(i
.e.aandc)by3
mul tiplyingthesecondandf ourthdi
gits(i
.e.bandd)by2
addi ngt hesef ourresul
t stogethertogiveat otal
di v
idingt histotalby10
r emai nderischeckdi git(e)
Wr
it
eanalgor i
thm,usi
ngpseudocodeorf l
owchartonly
,which
i
nputs100f ive-
digi
tbar
codesi nthef or
m a,b,c,
d, e
re-
calculat
esthecheckdigitforeachnumberandcheckswhet hert
hei
nputcheckdi
git(
e)
i
scor rect
outputsthenumberofbar codeswhi chwereenteredcor
rect
ly
e-
mai
l
:uzai
r_say
eed@hot
mai
l.
com,
Cel
l#0345-
2317709Page7