5
1 MMT-001: Programming and Data Structures Session 1: Familiarisation with compiling process The aim of this session and the next session is to familiarise the student with the process of compiling and running C programs. Program 1 Modify the program in unit1-prog1.c so that it outputs This is very easy!! Program 2 Modifying the values in the file unit1-prog8.c to the following, compiling, running and seeing the output: 1. x = 12, y = 13 and x = 11, y = 14 2. x = 1.2, y = 4.1 and x = 0.2 and y = 5 Program 3 1. Calculating the integral ! !!! ! ! ! by actual integration and comparing it with values obtained from the program unit1-simpsonf.c. 3. Changing the function to a) ! b) ! and comparing the values given by the program with the values got by actual integration. Session 2: Familiarisation with compiling process Program 1 Inserting printf() statements in unit3-prog1.c page 53, Block 1, compiling and running it to check the answer. Program 2 Compiling and running the file unit3-prog2.c in page 54 of Block 2 to check the answer for the exercise E3) of Unit 3. Program 3

MMT-001: Programming and Data Structures

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: MMT-001: Programming and Data Structures

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

Page 2: MMT-001: Programming and Data Structures

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

Page 3: MMT-001: Programming and Data Structures

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

Page 4: MMT-001: Programming and Data Structures

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

Page 5: MMT-001: Programming and Data Structures

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.