
ALGORITHMîANDîDATAîSTRUCTUREî1
Lecturer:îMUGHEîGODLOVE
Exerciseî1
Writeîanîalgorithmîthatîdisplaysîtheîmessageîî˘ Hello.
Exerciseî2
Writeîanîalgorithmîthatîallowsîtheîuserîtoîenterîtwoînumbersîandîdisplaysîtheirîproduct.
Exerciseî3
WriteîanîalgorithmîthatîexchangesîtheîvaluesîofîtwoîintegersîAîandîBîenteredîbyîtheîuser,îthen
displaysîthemîafterîtheîswap.
Exerciseî4
Writeîanîalgorithmîthatîdeterminesîwhetherîanîintegerîenteredîbyîtheîuserîisîevenîorîodd.
Exerciseî5
Writeîanîalgorithmîthatîdisplaysîtheîlargestîofîthreeîintegersîenteredîbyîtheîuser.
Exerciseî6
Writeîanîalgorithmîthatîevaluatesîaîgradeîenteredîbyîtheîuser.îIfîtheîgradeîisîgreaterîthanî10,îdisplay
î˘ Passed,îotherwiseîdisplayîî˘ Failed.î(Note:îtheîgradeîisîbetweenî0îandî20.)
Exerciseî7
Writeîanîalgorithmîthatîasksîtheîuserîtoîenterîtwoînumbersîmîandînîandîthenîtellsîwhetherîthe
productîofîtheîtwoînumbersîisîpositive,înegative,îorîzero.
Exerciseî8
Writeîanîalgorithmîthatîcalculatesîtheîabsoluteîvalueîofîanîintegerîenteredîbyîtheîuser.
Exerciseî9
Writeîanîalgorithmîthatîcalculatesîtheîaverageîofîthreeîintegersîenteredîbyîtheîuser.
Exerciseî10
Aîshopîgivesîaî15%îdiscountîforîpurchasesîoverî200îunits.îWriteîanîalgorithmîthatîreadsîtheîtotal
priceî(beforeîtax),îappliesîtheîdiscountîifîapplicable,îandîaddsî20%îVAT,îthenîdisplaysîtheîfinal
total.
Exerciseî11
Aîphotocopyîcenterîcharges:î0.25îperîcopyîforîtheîfirstî10îcopies,î0.20îperîcopyîforîtheînextî20
copies,îandî0.10îperîcopyîforîanyîcopyîbeyondîthat.îWriteîanîalgorithmîthatîreadsîtheînumberîof
copiesîmadeîandîdisplaysîtheîtotalîcost.
Exerciseî12