MMT-001: Programming and Data Structures

Preview:

Citation preview

1

MMT-001:ProgrammingandDataStructures

Session1:Familiarisationwithcompilingprocess

TheaimofthissessionandthenextsessionistofamiliarisethestudentwiththeprocessofcompilingandrunningCprograms.

Program1

Modifytheprograminunit1-prog1.csothatitoutputsThis is very easy!!

Program2

Modifyingthevaluesinthefileunit1-prog8.ctothefollowing,compiling,runningandseeingtheoutput:

1. x=12,y=13andx=11,y=142. x=1.2,y=4.1andx=0.2andy=5

Program3

1.Calculatingtheintegral !!!!!

𝑑𝑥 !! byactualintegrationandcomparingitwithvalues

obtainedfromtheprogramunit1-simpsonf.c.

3.Changingthefunctiontoa)𝑥!b)𝑒!andcomparingthevaluesgivenbytheprogramwiththevaluesgotbyactualintegration.

Session2:Familiarisationwithcompilingprocess

Program1

Insertingprintf()statementsinunit3-prog1.cpage53,Block1,compilingandrunningittochecktheanswer.

Program2

Compilingandrunningthefileunit3-prog2.cinpage54ofBlock2tochecktheanswerfortheexerciseE3)ofUnit3.

Program3

2

Completingtheprogramunit3-prog0.cinpage71ofBlock1,whichisgivenasthesolutiontoexerciseE1)ofUnit3,bygivingvaluesfortheremaining3casesandcompilingandrunningtheprogramtochecktheoutput.

Program4

Modifyingtheprograminunit3-prog0.csothatitreadsthevalueofaandbusingscanf()insteadofincludingthevaluesintheprogramitself,modifyitsothat

itreadsthevaluesofaandbusingscanf().Checkingtheprogrambycompilingandrunningitwith4differentvaluesofaandbcoveringallthe4cases.

Program5

Writingaprogramthatpromptstheuserforbasicpayandcalculatesandprintsbasic+

HRA(30%ofbasic)+DA(46%ofbasic).

Session3

Program1

Writingaprogramsimilartounit2-ex7ans.cinpage45ofBlock1thatchecksforoverflowinmultiplicationwhenthetwooperandsareunsignedlongandwhentheyarelongdouble.Theprogramshouldalsoprinttheoverflowwhenitoccurs.

Program2

WritingaprogramthatpromptsforanaturalnumbernandprintsthenthFibonacci

number.ItshouldalsoprintanerrormessageiftheFibonaccinumberisbiggerthan

ULONG_MAX.

Program3

WritingaprogramthatfindallprimeslessthanULONG_MAXandsavesitinafilecalledprimes.

Session4

WritingaCfunctiontodeterminethenumberofdaysbetweentwodatespassedtoit.

Session5

3

Program1

WritingafunctionthatevaluatesthepolynomialbyHorner’smethod.Horner’smethodis

asfollows:If

𝑓 𝑥 = 𝑎!𝑥! + 𝑎!!!𝑥!!! +⋯+ 𝑎!𝑥 + 𝑎!,theHorner’smethodisgivenbytheequation

𝑓 𝑥 = ( … 𝑎!𝑥 + 𝑎!!! 𝑥 + 𝑎!!! 𝑥 +⋯+ 𝑎! 𝑥 + 𝑎!)

Itshouldpromptforthecoefficientsofthepolynomial,storethevaluesinanarray,

promptthevalueforwhichthepolynomialistobeevaluatedandevaluateandprintthe

value.Thefunctionshouldbeabletoevaluateanypolynomialofdegreelessthan20.Thefunctionshouldbecheckedbywritingaprogramthatcallsit.

Program2

WritingfunctionssimilartoHorner’smethodforevaluating𝑓!(𝑥)and𝑓!(𝑥)where𝑓!(𝑥)and𝑓!(𝑥)aredefinedasfollows:If𝑓 𝑥 = 𝑎!𝑥! + 𝑎!!!𝑥!!! +⋯+ 𝑎!𝑥 + 𝑎!,then

𝑓! = 𝑎!𝑥! , 𝑓! 𝑥 = 𝑎!𝑥!!!!!!! !"!#

!!!!!! !""

Notethat𝑓 𝑎 = 𝑓! 𝑎 + 𝑓!(𝑎)and𝑓 −𝑎 = 𝑓! 𝑎 − 𝑓! 𝑎 .Itiseasytoshowthat,ifthepolynomial𝑓(𝑥)hasintegercoefficientsandhasarationalroot!

!,thenp|𝑎!andq|𝑎!.In

particular,ithasanintegerroota,thena|𝑎!.Writingafunctionforcheckingwhetherapolynomial𝑓(𝑥)hasintegerrootsbyfindingthevalueof𝑓(±𝑎)foralldivisorsofaof𝑎!

Program3

Writingaprogramthatcomputesthevalueoftan!! 𝑥usingthepowerseriesexpansion

𝑥 −𝑥!

3+𝑥!

5−⋯

Session6

ProgramtoevaluatedefiniteintegralsofafunctionforarbitrarynumberofintervalsusingSimpson’sonethirdrule.

Session7

4

Program1

Programforsolvingequationsbybisectionmethod.

Program2

Programforsolvingalgebraicequationsbyfalseposition(regulafalsi)method.

Session8

ProgramtosolveanintermediatevalueproblembyRunge-Kuttamethod

Session9

Program1

Currencyconverterprogramusingswitch()

Program2

ProgramforfindingmaximumnumberofrealrootsusingDescartesRuleofSigns.

Session10

Program1

Programforbinarypoweringalgorithm

Program2

Programforfindingtheorderof𝑎 ∈ 𝒁!𝒁foraprimep.

Session11

Program1

Programforlinearregression

Program2

Programtofitatranscendentalcurveoftheform𝑌 = 𝑎𝑋!foragivensetofdata.

Session12

5

Programforcreatingan×narrayoffloatusingcalloc().

Session13

ProgramforfindingtheinverseofamatrixusingGauss-Jordanmethod.

Session14

Programforworkingwithrationalnumberusingstruct.

Session15

Programthatmaintainsatelephonedirectoryinafile.

Session16

Programforadministeringanobjectivetypetest.

Session17

Programtocreatealinkedlistwhichholdsthenamesofthecities,sortsthelistandprintsthelist.

Session18

Program1

Programforreversingastringusingastack.

Program2

Programtocheckwhetherthebracketsareproperlymatched.

Session19

Programforimplementingaqueuecontainingintegersasalinkedlistbyimplementingfunctionsforcreationofthequeue,enqueueanddequeue.

Session20

Programtocreateabinarysearchtree,insertwords,doanin-order,pre-orderandpost-ordertraversalsofthetreesandlistthekeysineachnodetraversed.