0% found this document useful (0 votes)
15 views

C Lab

The document outlines a course on problem-solving using C programming, detailing its objectives, outcomes, and assessment structure. It includes specific programming assignments such as converting miles to kilometers, processing supermarket coins, calculating water bills, and finding prime numbers. Each assignment provides problem statements, input/output requirements, and sample test cases for student practice.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

C Lab

The document outlines a course on problem-solving using C programming, detailing its objectives, outcomes, and assessment structure. It includes specific programming assignments such as converting miles to kilometers, processing supermarket coins, calculating water bills, and finding prime numbers. Each assignment provides problem statements, input/output requirements, and sample test cases for student practice.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Pr

obl
em Sol
vi
ngwi
th'
C'Lab
(
Commont
oal
lbr
anches)

CSE117 Credi
ts:
1.5
Pract
ical
:3Per
iods Sessi
onalMar
ks:
50
EndExam: 3Hours EndExam Mar
ks:
50

Pr
erequi
sit
e:Concept
sofPr
obl
em Sol
vi
ng&Comput
erPr
ogr
ammi
ngi
nC

Cour
seObjecti
ve:
 Thecourseaimsatt
ransl
ati
nggi
venal
gor
it
hmst
oawor
kingandv
ali
dpr
ogr
am

Cour
seOut
comes:

Af
tercompl
eti
onoft
hiscour
se,
ast
udentwi
l
lbeabl
eto:
1. Devel
opCprogramsusi
ngoper
ator
s
2. Wri
teCprogramsusi
ngcondi
ti
onalst
ruct
ures
3 Wr
it
eCpr
ogr
amsusi
ngi
ter
ati
vest
ruct
urear
ray
sandst
ri
ngs
4. I
nscr
ibeCpr
ogr
amst
hatusePoi
nter
stoandf
unct
ions
5. Dev
elopacpr
ogr
am f
ori
mpl
ement
inguserdef
inedt
ypesandf
il
epr
ocessi
ng

PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2
CO1 3 3 3 3 3 3 3 2 3 3 3 3 3 3
CO2 1 2 2 2 1 2 2 2 3 1 1 1 2 2
CO3 2 2 2 3 1 2 1 2 2 1 1 1 1 1
CO4 2 2 2 3 1 2 1 2 2 1 1 1 1 1
CO5 2 2 2 2 1 2 1 2 2 1 1 1 1 1

MI
NIMUM SETOFSAMPLEPROGRAMS

1.CONVERTI
NGMI
LESTOKI
LOMETERS

PROBLEM STATEMENT:Yoursummersur v
eyi
ngjobrequi
r esyoutost
udysomemaps
thatgi
vedistancesi
n ki
l
ometersandsomethatusemi l
es.Youandy ourcoworker
s
pref
ertodealinmetri
cmeasurement
s.Wri
teaprogr
am t hatperf
ormsthenecessar
y
conver
sion.

Probl
em I
nput:mil
es /
*thedist
ancei
nmi l
es*
/
Probl
em Out
put:kms /
*thedist
ancei
nkil
ometer
s*/
Relev
antFor
mula:1mil
e=1.609kil
ometer
s

1
Desi
gnal
gori
thm ,
flowchar
t,pr
ogr
am usi
ngt
heabov
edat
arequi
rement
sfort
hegi
ven
pr
oblem.
Tryt
hesampl
etestcasesgi
venbel
ow:

SAMPLETESTCASES I
NPUT OUPUT

Testcase1 10 16.
09

Testcase2 2 3.
218

2.SUPERMARKETCOI
NPROCESSOR

PROBLEM STATEMENT: Youar edraf


ti
ngsof t
waref orthemachinesplacedatthe
fr
ontofsuper marketstoconv
ertchangetopersonal
izedcredi
tsli
ps.Inthi
sdraft
,the
userwil
lmanuallyentert
henumberofeachkindofcoininthecoll
ecti
on,butint
hefi
nal
versi
on,t
hesecount swil
lbeprov
idedbycodethatint
erfaceswit
hthecountingdev
ices
i
nt hemachine.

Probl
em Inputs
charfi
rst,mi
ddle,l
ast /*acust omer'
siniti
als*
/
i
ntdollar
s /*numberofdol lars * /
i
ntquar t
ers /*numberofquar t
ers * /
i
ntdimes /*numberofdi mes * /
i
ntnickels /*numberofni ckel s */
i
ntpennies /*numberofpenni es * /
Probl
em Out put
s
i
nttotal_
doll
ars /*totaldoll
arv alue */
i
ntchange /*leftov
erchange * /
Addit
ionalProgram Variabl
es
i
nttotal_
cents /*totalval
uei ncents* /

Desi
gnalgori
thm,
flowchart,
program usi
ngtheabov
edat
arequi
rement
sfort
hegi
ven
pr
oblem Tr
ythesampletestcasesgivenbel
ow:

TESTI
NGTI
P:

Totestthi
sprogram,tryr
unningitwit
hacombinat
ionofcoinsthatyi
eldanexactdoll
ar
amountwithnol ef
toverchange.Forexampl
e,1doll
ar,8quart
ers,0dimes,35nickels,
and25penni esshoul dyiel
dav al
ueof5dol l
arsand0cent s.Thenincreaseand
decreasethequanti
tyofpenni esby1( 26and24pennies)tomakesur ethatthese
casesarealsohandl
edproperly
.

SAMPLE TEST I
NPUT OUPUT

2
CASES

Testcase1 Ty
pei
nyour3i
nit
ial
sandpr
essr
etur
n>JRH JRHCoi
nCr
edi
t

JRH,
pleaseent
ery
ourcoi
ninf
ormat
ion. Dol
l
ars:
9

Numberof$coi
ns>2 Change:26
cent
s
Numberofquar
ter
s>14

Numberofdi
mes >12

Numberofni
ckel
s>25

Numberofpenni
es>131

Testcase2 Ty
pei
nyour3i
nit
ial
sandpr
essr
etur
n>JRH JRHCoi
nCr
edi
t

JRH,
pleaseent
ery
ourcoi
ninf
ormat
ion. Dol
l
ars:
11

Numberof$coi
ns>3 Change:26
cent
s
Numberofquar
ter
s>12

Numberofdi
mes >14

Numberofni
ckel
s>50

Numberofpenni
es>175

3.
WATERBI
LLPROBLEM

PROBLEM STATEMENT: Writ


eapr ogram thatcomput esacust omer’
swat erbil
l.The
bil
lincl
udesa$35wat erdemandchar geplusaconsumpt i
on( use)chargeof$1.10for
everyt housand gal
lons used.Consumpt ion isfigured f
rom met erreadi
ngs ( i
n
thousandsofgal l
ons)t akenrecentl
yandatt heendoft hepr evi
ousquar t
er.Ifthe
customer’sunpai
dbalancei sgreat
erthanzer o,
a$2latechargeisassessedaswel l.

Probl
em Const ant
s
DEMAND_ CHG35.00 / *basicwaterdemandchar ge * /
PER_1000_ CHG1.10 / *chargeperthousandgallonsused * /
LATE_CHG2. 00 / *sur chargeonanunpai dbal
ance * /
Probl
em Inputs
i
ntprevious/ *meterreadingf r
om pr
ev i
ousquart
erinthousandsofgal
l
ons *
/
i
ntcurrent/ *meterreadingf r
om currentquar
ter */
doubl
eunpai d/*unpaidbal anceofpreviousbi
ll * /

3
Probl
em Out put
s
doublebill / *waterbil
l* /
doubleuse_char
ge/ *chargeforact
ual
wateruse */
doublelate_
charge/*chargef
ornonpaymentofpar
tofpreviousbal
ance */
RelevantFormulas
waterbill= demandcharge+usechar ge+unpai dbal
ance+appli
cabl
elat
echar
ge

Desi
gnalgori
thm ,
flowchar
t,pr
ogram usi
ngtheabov
edat
arequi
rement
sfort
hegi
ven
pr
oblem Tr
ythesampl et
estcasesgi
venbelow:

SAMPLE TEST I
NPUT OUPUT
CASES

Testcase1 Thi
sprogr
am fi
guresawat
erbi
l
lbased Bil
li
ncl
udes$2.
00
onthedemandcharge l
atechar
geonunpai
d
bal
anceof$71.
50
($35.
00)anda$1.
10per1000gal
l
ons
usecharge. Tot
aldue=$152.
50

A$2.
00surchargeisaddedt
oaccount
s
wi
thanunpaidbalance.

Enterunpaidbalance,prev
iousand
curr
entmet err
eadi ngsonseparatel
ines
aft
ertheprompt s.Press<r
eturn>or
<enter
>afterty
pi ngeachnumber .

Ent
erunpai
dbal
ance>$71.
50

Ent
erpr
evi
ousmet
err
eadi
ng>4198

Ent
ercur
rentmet
err
eadi
ng>4238

Testcase2 Thi
sprogr
am f
igur
esawat
erbi
l
lbased Bil
li
ncl
udes$2.
00
onthedemandchar
ge l
atechar
geonunpai
d
bal
anceof$71.
50
($35.
00)anda$1.
10per1000gal
l
ons
usechar
ge. Tot
aldue=$102.
00

A$2.00sur
char
geisaddedt
oaccount
s
wi
thanunpai
dbalance.

Enterunpaidbalance,
prev
iousand
curr
entmeterreadingsonseparatel
ines
aft
ertheprompts.Press<r
eturn>or

4
<ent
er>af
tert
ypi
ngeachnumber
.

Ent
erunpai
dbal
ance>$51

Ent
erpr
evi
ousmet
err
eadi
ng>4198

Ent
ercur
rentmet
err
eadi
ng>4137

4.PRI
MENUMBER

PROBLEM STATEMENT:
Giv
enaposi
ti
vei
ntegerN,cal
cul
atet
hesum ofal
lpr
imenumber
s
bet
ween1andN(
incl
usi
ve)
.
I
nput:
Thef i
rstl
i
neofi nputcontainsanintegerTdenot
ingt henumberoftestcases.T
test
casesf
oll
ow.Eachtestcasecont
ainsoneli
neofinputcont
aini
ngN.
Output:
Foreachtestcase,
inanewl
i
ne,
pri
ntt
hesum ofal
lpr
imenumber
sbet
ween1andN.
Const
rai
nts:
1≤T≤100
1≤N≤106
Desi
gnalgori
thm ,
flowchart,
progr
am usi
ngtheabov
edat
arequi
rement
sfort
hegi
ven
pr
oblem Tr
ythesampletestcasesgi
venbel
ow:

SAMPLETESTCASES I
NPUT OUPUT

Testcase1 2 10
5
17
10

Testcase2 2 17

7 17

10

5
5.BUBBLESORT

PROBLEM STATEMENT:
Thet
aski
stocompl
etebubbl
efunct
ionwhi
chi
susedt
oimpl
ement
Bubbl
eSor
t
Input:
Firstl
ineoft
heinputdenot
esthenumberoft
estcases'T'
.Fi
rstl
i
neoft
het
estcasei
s
thesizeofarr
ayandsecondli
neconsi
stsofar
rayelements.
Out
put:
Sor
tedar
rayi
nincr
easi
ngor
deri
sdi
spl
ayedt
otheuser
.
Const
raint
s:
1<=T<=100
1<=N<=1000
1<=arr
[i
]<=1000
Desi
gnalgori
thm ,
flowchar
t,pr
ogram usi
ngtheabov
edat
arequi
rement
sfort
hegi
ven
pr
oblem Tr
ythesampl et
estcasesgi
venbelow:

SAMPLETESTCASES I
NPUT OUPUT

Testcase1 2 13479
5 12345678910
41397
10
10987654321

Testcase2 1 02389

89320

6.TEXTEDI
TOR

PROBLEM STATEMENT:Desi gn and implement a pr


ogram to per f
orm edit
ing
operati
onsonal i
neoft ext.Youreditorshouldbeabletolocateaspeci f
iedtar
get
substr
ing,del
eteasubstring,andinsertasubstri
ngataspecif
iedlocat
ion.Theedit
or
shouldexpectsour
cestr
ingsofl essthan80character
s.

Probl
em ConstantMAX_LEN 100 / *maximum si
zeofast
ri
ng*
/
Probl
em Input
s
charsour
ce[MAX_LEN] /*sourcest
ri
ng* /
charcommand /
*editcommand* /
Probl
em Output
charsour
ce[MAX_LEN] /
*modi fi
edsourcest
ri
ng*/

6
Desi
gnalgori
thm ,
flowchar
t,pr
ogram usi
ngtheabov
edat
arequi
rement
sfort
hegi
ven
pr
oblem Tr
ythesampl et
estcasesgi
venbelow:

SAMPLE TEST I
NPUT OUPUT
CASES

Testcase1 Ent
ert
hesour
cest
ri
ng: Newsource:I
nter
net
usei
srapidl
y
>I
nter
netusei
sgr
owi
ngr
api
dly
.

EnterD(Del
ete)
,I(
Inser
t),
F(Fi
nd)
,or
Q(
Quit)>d

St
ri
ngt
odel
ete>gr
owi
ng

Testcase2 EnterD(Del
ete)
,I(
Inser
t),
F(Fi
nd)
,or '
.
'foundatposi
ti
on23
Q(Quit
)>F

St
ri
ngt
ofi
nd>.

7.ARI THMETICWITHCOMMONFRACTI ONS


PROBLEM STATEMENT:Youar eworkingprobl
emsi nwhi chy oumustdispl ayyour
result
sasintegerr
atios;ther
efore,youneedtobeabl et operf
orm computationswith
commonf r
acti
onsandgetr esultsthatarecommonf ract
ionsinreducedf orm.You
wantt owri
teaprogram thatwillal
lowyout oadd,subt
ract,
mul t
ipl
y,anddi
videseveral
pairsofcommonf r
actions.

Desi
gnalgor
it
hm,flowchart
,progr
am usi
ngt
heabov
edat
arequi
rement
sfort
hegi
ven
pr
oblem
Tryt
hesampletestcasesgi
venbel
ow:

SAMPLETESTCASES I
NPUT1 OUPUT

Testcase1 Enteracommonf r
act
ionast wo I
nput
i
ntegerssepar
atedbyaslash>3/-
4 i
nval
id—denominat
or
mustbeposit
ive

Testcase2 Enteracommonf r
acti
onastwoint
egers gcdof44and32?>4
separat
edbyaslash>3/4
find_
gcdret
urni
ng4
Enteranari
thmeti
coperat
or(
+,-
,
*,or/)
3/ 4+5/
8=11/ 8
>+

Ent
eracommonf
ract
ionast
wo

7
i
nteger
ssepar
atedbyasl
ash>5/
8

Ent
eri
ngf
ind_
gcdwi
thn1=44,
n2=32

Doanot
herpr
obl
em?(
y/n)
>n

8.FACTORIALOFANUMBER
PROBLEM STATEMENT:Fi
ndf
act
ori
alofagi
vennumbern.

Desi
gnalgori
thm ,
flowchar
t,pr
ogram usi
ngtheabov
edat
arequi
rement
sfort
hegi
ven
pr
oblem Tr
ythesampl et
estcasesgi
venbelow:

SAMPLE TEST I
NPUT1 OUPUT
CASES

Testcase1 Ent
eranumbert
ofi
ndf
act
ori
al>2 Fact
ori
alof2i
s4

Testcase2 Ent
eranumbert
ofi
ndf
act
ori
al>3 Fact
ori
alof3i
s6

9.COLLECTI NGAREAFORSOLAR- HEATEDHOUSE–FI LESANDFUNCTI ONS


PROBLEM STATEMENT :An ar chi
tectneeds a pr ogr am thatcan est imatet he
appropr i
atesi zef orthecol lectingar eaofasol ar
-heat edhouse.Det er
mi ningcol l
ect i
ng
areasi zer equi r
esconsi derationofsev eralf actors,i ncludingtheav eragenumberof
heatingdegr eeday sf ort hecol destmont hofay ear( thepr oductoft heav erage
diff
erencebet weeni nsideandout sidet emper aturesandt henumberofday si nt he
mont h),theheat ingr equirementpersquar ef ootoff loorspace, thef l
oorspace, andt he
effi
ciencyoft hecol l
ectionmet hod.Thepr ogr am willhav eaccesst otwodat afil
es.Fi l
e
hdd.txtcont ains number sr epresenting t he av erage heat i
ng degr ee day si nt he
const r
uctionl ocat i
onf oreachof12mont hs.Fi l
esol ar.t
xtcontainst heav eragesol ar
i
nsolation( rateinBTU/ dayatwhi chsol arradi ati
onf allsononesquar efootofagi ven
l
ocat i
on)f oreachmont h.Thef i
rstent ryineachf iler epresentsdat aforJanuar y,the
second, dataf orFebr uary,andsoon.

Probl em Input s
Av erageheat ingdegr eeday sf
il
e
Av eragesol arinsolati
onf i
le
heat_ deg_day s/ *averageheati
ngdegr eeday sforcoldestmont
h * /
coldest _mon / *coldestmonth( number1. .12) */
solar_ i
nsol/ *av er
agedai l
ysolarinsolat
ion( BTU/ft^
2)forcoldestmont
h *
/
heat ing_req / *BTU/ degreedayf t
^ 2forplannedt ypeconstr
uct
ion*/
ef fi
ciency / *%ofsol ari
nsol
ationconv ertedtousabl eheat*/
floor _space / *squar efeet*/

8
Program Variables
energy _
resrc/ *usabl
esol
arenergyav ai
l
ableincol
destmonth( BTUsobt
ainedf
rom 1
ft
^2ofcol l
ectingarea)*/
Probl
em Out puts
heat_loss / *BTUsofheatlostbyst r
uctur
eincoldestmonth* /
coll
ect _
area/ *approxi
matesi
ze( f
t^2)ofcol
lect
ingareaneeded*/

Thef
ormulaf
orapproximati
ngthedesi
redcol
l
ect
ingar
ea(
A)i
s:
A=heatl
oss/ener
gyr esource

Desi
gnalgor
it
hm ,fl
owchart,
progr
am usi
ngt
heabov
edat
arequi
rement
sfort
hegi
ven
pr
oblem
Tryt
hesampletestcasesgi
venbel
ow:
SAMPLETESTCASES I
NPUT OUPUT

Testcase1 Whatist
heappr
oxi
mat eheati
ng Tor eplaceheatlossof11350800BTU
r
equir
ement(
BTU/degr eeday i
nt hecol destmonth(month12)wi t
h
f
t^2)oft
hist
ypeofconstruct
ion? availablesolari
nsol
ati
onof500BTU/
ft
^2/day ,andan
=>9
eff
ici
encyof60percent
,useasol
ar
Whatper
centofsol
arinsol
ati
on col
l
ecti
ngareaof1221ft^
2.
wi
l
lbeconver
tedtousableheat
?

=>60

Whati
sthef
loorspace(
ft^
2)?

=>1200

Testcase2 Whatist
heappr
oxi
mat eheati
ng Tor eplaceheatlossof12612000BTU
r
equir
ement(
BTU/degr eeday i
nt hecol destmonth(month12)wi t
h
f
t^2)oft
hist
ypeofconstruct
ion? availablesolari
nsol
ati
onof500BTU/
ft
^2/day ,andan
=>10
eff
ici
encyof60percent
,useasol
ar
Whatper
centofsol
arinsol
ati
on col
l
ecti
ngareaof1221ft^
2.
wi
l
lbeconver
tedtousableheat
?

=>60

Whati
sthef
loorspace(
ft^
2)?

=>1200

9
Q10.UNI VERSALMEASUREMENTCONVERSI ON
PROBLEM STATEMENT:Desi gnapr ogram thattakesameasur ementinoneuni t(e.g.
,
4.5quarts)andconv er
tsi ttoanot heruni t(e.g.
,li
ters)
.Forexampl e,thisconversi
on
request 450km mi l
es woul dr esul
tint hisprogram output At tempti
ngconv er
sionof
450.0000km tomi l
es...450. 0000km =279. 6247mi l
es.Thepr ogram shouldproduce
aner r
ormessagei faconv er
si onbetweent wouni tsofdifferentclasses(e.g.
,liquid
volumet odist
ance)isrequest ed.Thepr ogr
am shoul dtakeadat abaseofconv ersi
on
i
nformation fr
om an i nput f i
le before accept i
ng conv ersion problems ent er
ed
i
nteracti
vel
ybyt heuser.Theusershoul dbeabl etospecifyunit sei
therbyname( e.g.
,
kil
ograms)orbyabbreviati
on(e. g.
,kg).

StructuredDat aTy pe
uni t
_tmember s:
name / *char acterst r
ingsuchas" mi l
li
grams" *
/
abbr ev / *shor terchar act erstri
ngsuchas" mg" */
class / *char acterst ri
ng" l
iqui
d_ vol
ume" ,
"distance",or"mass"* /
standar d/ *numberofst andar duni t
sthatar eequi valenttothisuni
t* /
Problem Const ants
NAME_ LEN 30 / *st orageal l
ocatedf orauni tname */
ABBREV_ LEN 15 / *st orageal l
ocatedf orauni tabbr ev i
ation */
CLASS_ LEN 20 / *st orageal l
ocatedf ora measur ementcl ass * /
MAX_ UNI TS 20 / *maxi mum numberofdi f
ferentunits handl ed */
Problem I nput s
uni t
_tunits[MAX_ UNI TS]/ *ar r
ayr epresentinguni tconversionfactor
sdatabase */
doubl equant i
ty /*v al
uet oconv ert * /
charol d_uni t
s[ NAME_ LEN]/ *nameorabbr eviati
onofuni t
st obeconvert
ed * /
charnew_ units[NAME_ LEN]/ *nameorabbr eviati
onofuni tst oconvertt
o * /
Probl em Out put
Messagegi vingconv ersion.

Datafile uni
ts.txt:
mi l
es mi distance 1609. 3
kil
omet ers km distance 1000
yards yd distance 0.9144
met ers m distance 1
quarts qt li
quid_v olume 0. 94635
li
ters l li
quid_volume 1
gall
ons gal l
iquid_v olume 3. 7854
mi l
li
li
ters ml li
qui d_volume 0. 001
kil
ograms kg mass 1
grams g mass 0.001
slugs slugs mass 0.14594
pounds l
b mass 0.43592

Desi
gnal
gor
it
hm ,
flowchar
t,pr
ogr
am usi
ngt
heabov
edat
arequi
rement
sfort
hegi
ven

10
pr
obl
em

Tr
ythesampl
etestcasesgi
venbel
ow:

SAMPLETESTCASES I
NPUT1 OUPUT

Testcase1 Enteraconv
ersi
onpr
obl
em orq >450km mi
l
es
toquit
.
Attemptingconv
ersi
onof
Toconver
t25ki
lomet
erst
o 450.0000km tomil
es...
mi
les,
youwoul
denter
450.
0000km =279.
6247mi
l
es
>25ki
l
omet
ersmi
l
es

or
,al
ter
nat
ivel
y,

>25km mi

Testcase2 Enteraconv
ersi
onpr
obl
em orq >100met
ersgal
l
ons
toquit
.
Attemptingconver
sionof
>2.
5qtl 100.0000meterstogall
ons...

Attempti
ngconver
sionof2.
5000 Cannotconver
tmeters
qttol... (
dist
ance)togal
lons
(
li
quid_
volume)
2.5000qt=2.
3659l

Ent
eraconv
ersi
onpr
obl
em orq
t
oquit
.

ADDI
TIONALPROGRAMS
Pr
obl
em sol
vi
ngpr
ogr
ams:

1.Chocol atef east:Litt


leBobl oveschocol ates,andgoest oast or
ewi th$Ni nhi spocket .
Thepr i
ceofeachchocol at eis$C.Thest oreoffersadi scount :f
orev eryM wr appershe
givest othest ore,heget sonechocol atef orfree.Howmanychocol at esdoesBobgett o
eat ?Not e:Ev aluat
ethenumberofwr apsaf tereachst ep.Dot hi
sunt i
lyouhav eenough
wr apst obuynewchocol ates.
2.Angr yPr ofessor:Thepr ofessorisconduct i
ngacour seonDi screteMat hemat icstoa
classofNst udents.Hei sangr yatt hel ackoft hei
rdisci pl
ine,andhedeci dest ocancel
thecl assiftherear el
esst hanKst udent spr esentaftert heclassst arts.Givent hearri
v al
ti
meofeachst udent,
y ourt askistofindouti ftheclassget scancel ledornot .
3.Div i
sibleSum Pai r
s:Youar egivenanar rayofni nteger sandaposi t
ivei
nt eger,k.Find
andpr i
ntthenumberof( i
,j)pair
swher ei<j andai +ajisev enlydivi
si blebyk.
4.Sher l
ockAnd Val id Stri
ng:A “ val
i
d”st ri
ng isa st ring S such t hatforal ldist
inct

11
charactersinSeachsuchchar acteroccursthesamenumberoft i
mesi nS.Not e:The
l
ogicoft hesoluti
onisasf ol
lows:countt hecharactercount
sforeachcharacter.Note:
i
ftheyar eallequal–itmeanst hatal
lcharactersoccurexactl
yNt i
mesandt herei sno
remov alneeded.if2ormor ehav elessormor echaract
ers–t her
eisnowayt ofixthe
str
inginjust1r emoval
.ifexactly1charhasadi f
fer
entcountthanallot
hercharacters–
remov ethischarcomplet
elyandSi sf
ixed.

5.IceCream Parl
or:SunnyandJohnnyt ogetherhaveM doll
arstheywantt ospendonice
cream.Theparloroff
ersNflav
or s,
andt heywanttochooset woflavorssothattheyend
upspendingthewholeamount .Youaregi venthecostofthesefl
avors.Thecostofthe
i
t hfl
avori
sdenotedbyci.Youhav etodisplaytheindi
cesofthetwof l
avorswhosesum
i
sM.

6.‘
Mi ssi
ngNumber s’
:Numer os,t
heArti
st,
hadtwol i
stsAandB, suchthatBwasa
permutat
ionofA.Numer oswasv er
yproudoftheseli
sts.Unf
ortunat
ely,
whi
le
tr
ansport
ingthem f
rom oneexhibi
ti
ontoanother,
somenumber sf r
om Agotl
eftout
.
Cany ouf
indthenumbersmi ssi
ng?

7.Alt
ernati
ngCharacter
s:Johnlikesstri
ngsinwhichconsecut
ivecharacter
sar edi f
fer
ent
.
Forexample,
helikesABABA, whilehedoesn’
tli
keABAA.Gi v
enast r
ingcontaining
charact
ersAandBonl y,hewant stochangei
tintoastri
nghelikes.Todot hi
s, heis
al
lowedtodelet
et hecharact
ersinthestri
ng.

8.GameOfThr ones:I: Dothrakiarepl anni


nganat tackt ousur pKingRober t
'sthrone.
KingRober tlearnsoft hisconspi r
acyf r
om Rav enandpl anstolockt hesi
ngledoor
throughwhi cht heenemycanent erhi skingdom door .But ,t
olockt hedoorheneedsa
keyt hati
sananagr am ofapal indrome.Hest art
st ogot hr
oughhi sboxofst ri
ngs,
checkingtoseei ft heycanber earrangedi ntoapal i
ndr ome.Forexampl e,giventhestri
ng
,s=[aabbccdd]onewayi tcanbear rangedi nt
oapal i
ndr omei sabcddcba.
9.Lifeandev er yt
hing:Yourpr ogr am ist ouset hebrute-forceapproachi nordertofindthe
Answert oLi fe,theUni verse,andEv erythi
ng.Mor epreci sel
y..
.rewritesmallnumber s
from inputtoout put.Stopprocessi ngi nputafterreadingi nthenumber42.Al lnumbers
atinputarei nteger sofoneort wodi git
s.

i
nput
:12232242

out
put
:122322

10.Fil
li
ngJars:Ani
meshhasNempt ycandyjars,numberedfr
om 1t oN,withi
nfi
nit
e
capacit
y.Heper
formsM operat
ions.Eachoperati
onisdescri
bedby3integersa,bandk.
Here,aandbareindi
cesofthejar
s,andkist henumberofcandiestobeaddedinsi
de
eachjarwhosei
ndexliesbet
weenaandb( bothincl
usi
ve)
.Cany outel
ltheaver
age
numberofcandi
esafterM oper
ati
ons?

Ref
erenceBooks:

(
1)Jer
iR.Hanl
y,El
l
iotB.
Kof
fman,Pr
obl
em sol
vi
ngandpr
ogr
am Desi nC,7th
gni
Edi
ti
on

12
(
2)ComputerScience:AStructur
edPr ogr
ammingAppr oachUsi
ngC,B.A.For
ouzan
andR.F.Gi
lberg,Thi
rdEdit
ion,CengageLear
ning.
(
3)Diet
al&Dei
tal ,
CHowt oPr ogram 7/E,
PHIPubli
cati
ons

WebRef
erences:
 ht
tps:
//www.
spoj
.com/

 ht
tps:
//pr
oject
eul
er.
net
/

 ht
tps:
//www.
hacker
ear
th.
com/
pract
ice/

 ht
tps:
//www.
codechef
.com/

 ht
tps:
//onl
i
necour
ses.
npt
el.
ac.
in/

I
nst
ruct
ionst
othei
nst
ruct
or:

Thi
slabcour
seconsistsoft
wosetofpr
ogr
ams
1)Mini
mum setofsampleprogr
ams
2)Addi
ti
onalsetofpr
ograms

Minimum setofsampl
epr
ogramsar
edesi
gneduni
twisecover
ingall
thet
opi
csi
nthe
theor
y.
Addit
ionalsetofpr
ogr
amsar
edesi
gnedbasi
ngonprobl
em sol
ving

Sessi
onalmar ks: 50marks
1)Dail
yEv aluati
on(I
ncludesRecor
d,Obser
vat
ion&r
egul
arper
for
mance)–30
mar ks
2)Att
endance–5mar ks
3)Int
er nalExam –10mar ks
4)VivaVoce–5mar ks

Dai
l
yEv
aluat
ion(
30mar
ks)

EveryStudentmustexecutemi ni
mum setofsampl eprogr amstosecure60%ofmar ks
i
nDai l
yEv al
uationi
.e.18Marksandt oappearinexter
nal examinati
on.
Inaddit
iontothatifastudentf
inishestheminimum setand5pr ogr
amsfrom addit
ional
setofprogramswoul dsecure80%ofmar ksi
nDai l
yEvaluationi
.e.24Marks.
Ifastudentfi
nishesallt
heprogramsi nboththesetswillsecure100%ofmar ksinDaily
Eval
uation

I
nter
nal
Exam (
10mar
ks)

 Everyst
udentisgiven4quest
ionsintheint
ernal
exam outofwhichthediffi
cul
ty
l
evelof2questionsiseasy/medi um and2questi
onsofdiff
icul
tyleveli
shigh
 Eacheasy/medi um lev
elquesti
oncarri
es20%ofmar ksanddiff
icult
ylevel
questi
oncarr
ies30%ofmar ks

13
Ext
ernal
Exam (
50mar
ks)

 Vi
vavoce–10mar ks
 Wri
teup+Execut
ion–40mar
ks

Wr
it
eup+Execut
ion(
40mar
ks)

 Everyst
udentisgiven4questi
onsintheext
ernal
exam outofwhi
cht hediff
icul
ty
l
evelof2questionsiseasy/medi um and2questi
onsofdif
fi
cul
tyleveli
shi gh
 Eacheasy/medi um lev
elquesti
oncarri
es30%ofmar ksanddi
ff
icult
ylevel
questi
oncarr
ies20%ofmar ks.

14

You might also like