Anda di halaman 1dari 11

LabAssignments: //PracticeLinuxcommands 1.Writearecursivefunctionthatwillgenerateandprintthefirstnfibonaccinumbers 2.Usingpointers,writeafunctionthatreceivesacharacterstringandacharacteras argument and deletesalloccurrencesof this characterinthestring. The function shouldreturnthecorrectedstringwithnoholes 3.Givenanarrayofsortedlistofintegernumbers,writeafunctiontosearchfora particularitemusingthemethodofbinarysearch.Andalsoshowhowthisfunction maybeusedinaprogram.

.Usepointersandpointerarithmetic 4.Writeaprogramtoextractaportionofacharacterstringandprinttheextracted string.Assumethatmcharactersareextracted,startingwithnthcharacter 5.WriteaprogramtoprintthePascaltrianglefor10rows 6.Writeaprogramthatwillreadapositiveintegerandprintitsbinaryequivalent 7.Developaprogramtoaddandmultiplytwomatrices 8.Developaprogramtosortnstrings.Usearrayofpointers. 9.Developaprogramtoreadlinesandprintonlythosecontainingacertainword 10.Writeaprogramtosortalltheelementsof4by4matrix.Amagicsquareisa squarearrayofpositiveintegerssuchthatthesumofeachrow,column,anddiagonal isthesameconstant. ForExample: 16 3 2 13 5 10 11 8 9 6 7 12 4 15 14 1 Given above is a magic square whose constant is 34. Write a program to determinewhetherornotthegivensquareisamagicsquare. 11.Writeafunctiontogetthetransposeofamatrix. 12.Writeaprogramtoreverseastringusingpointers 13.DevelopaprogramtocalculatenPrandnCrgivennandr 14.Writeaprogramthatwillopenafileandreportonthenumberoflines,characters, andwordsinafile.Havethenameofthefiletobeopenedappearasacommandline argument. 15.Writeaprogramtoswapcontentsoftwovariableswithoutusingthirdvariable. 16.Writeaprogram,whichwilldeleteonlyoddnumbersfromalinkedlistofintegers. 17.Writeaprogramtoremovetrailingblanksandtabsfromeachlineofinput,andto deleteentirelyblanklines.

18.Writeafunctionsmallestthattakesthreeintegers,x,y,zandreturnsaninteger smallestamongthem. 19.Anintegerissaidtobeprimeifitisdivisibleonlyby1anditself.Forexample2, 3,5and7areprime,but4,6,8,and9arenot. 20.Writeafunctionthatdeterminesifanumberisprime. 21.Usethisfunctioninaprogramthatdeterminesandprintsalltheprimenumbers between1and100. 22.Writetheversionsofthelibraryfunctionsstrncpy,strncat,andstrncmp,which operateonatmostthefirstncharactersoftheirargumentstrings. Forexample, strncpy(s,t,n)copiesatmostncharactersofttos. 23.Writeaprogramthatreadsthreenonzerofloatvaluesrepresentingthesidesofa triangle.Calculatetheareaofthetriangle 24.Writeaprogramtoencrypt/decryptafileusingbitwiseoperatorXOR(^). 25.Createadatabasemanagementsystemformanagingstudentsinformation.Add thefeatureslike,add,delete,modify,search,sortetc.Theprogramshouldalsohave thefeatureforgeneratingreportsinthetextfileformat.Thetextfileshouldcontain titlesunderwhichalltheinformationislistedinatabularform. 26.WriteaprogramtoremoveallthecommentsfromaCprogram. 27.Developaprogramthatreadsafilecontainingalistofnumbers,andthenwrites twofiles,onewithallnumbersdivisiblebythreeandanothercontainingalltheother numbers 28.Takeoneofyourpreviousprogramsandrunitusingtheinteractivedebuggerto examineseveralintermediatevalues 29.Developaprogramthatcountsthenumberofbitsinacharacterarray.Optimizeit through the use of register integer variables. Time ito severaldifferent arrays of differentsizes.Howmuchtimedoesyousave? 30.TryexamplesbyembeddingassemblycodeinCandobservetheperformance 31.Developaprogramthatreadsalinkedlistofnumbers,andthenwritestwolinked lists,onewithallnumbersdivisiblebythreeandanothercontainingalltheother numbers 32.Createaprogramwithfunctionsforcreation,insertion,deletion&searchingina linked list. The main should interactively read a command and invoke above functions. 33.Writearecursivefunctionforprintingtheelementsofalinkedlistinthereverse order. 34.Writeafunctiontoreversealinkedlist. 35. Write a program to add two polynomials. Use linked list representation for polynomials. 36.Implementadoublylinkedlistwithfunctionstoaddordeletefromheadortailof thelist.

37.CreateaprogramforStackwithneededfunctions,usingarrayimplementation andsolvethefollowing i. Evaluationofpostfixexpression ii. ConvertingInfixtopostfix 38. Implement a program for Queue with necessary functions using linked list implementation 39.ImplementaprogramforDequewithfunctionstoaddordeletefromeitherend. 40. ImplementCprogramtosortNnumberofstudentrecordsusing 1.Bubblesort 2.InsertionSort 3.HeapSort 4.Quicksort 5.MergeSort 41. SearchforaparticularstudentdetailsfromthesortedstudentlistusingBubble Sort 42. Givenapostfixexpression,constructanexpressiontreeandincludethefollowing functions Inordertraversal Heightofthetree MirrorImage Noofnodes Preordertraversal Postordertraversal 43. CreateBinarySearchTreeADTwiththefollowingfunctions Insertion Deletion Find Find_Min Find_Max 44. GivenInorderandPreordertraversalsofabinarytree,constructthebinarytree. 45. Writeanonrecursiveroutinetotraversethebinarytreeininorder 46. CreateanAVLtreebyincludingfunctionalityforinserting,singlerotationleft, singlerotationright,doublerotationleft&doublerotationright 47.Developaprogramtofindtheshortestpathinagraph 48.CaseStudyRealTimeSystemdesignusingsoftwareengineeringprinciples 49.CaseStudyRealTimeSystemdesignusingsoftwareengineeringprinciples

50.CaseStudyRealTimeSystemdesignusingsoftwareengineeringprinciples

AdditionalExercises 1.Develop a C program to perform operations (+,*,, / and %) on two whole numbers.Identifysuitabledatatypestorepresentthenumbersandresultantvalues 2.Develop a C program to add two operands and store the result in one of the operandusingadditonassignmentoperator 3.DevelopaCprogramtocalculatesimpleinterestusingtheformulaI=PTR/100. DisplayInterestwithtwodigitprecisionafterdecimalpoint 4.DevelopaCprogramhavingfollowinglogic.Ifiis20orjis20,displayas Atleast onevariableishaving20otherwisedisplayBothvariablesarenothaving20.If iislessthanorequalto40andjislessthanorequalto40,Itshoulddisplay Both arelessthanorequalto40otherwise,itshoulddisplayas Botharenotlessthan orequalto40.Implementthisusingifelsestatementaswellaswithconditional operator. 5.DevelopaCprogramwhichacceptscharactertypedataitemfromuser.Incaseif userTyped Aora,itshoulddisplayAforApple Borb,itshoulddisplayBforBat Dord,itshoulddisplayDforDog Forf,itshoulddisplayFforFan Insteadoftheabove4characters,ifusertypesanyothercharacter,itshould displayCharacterisnotintherange.Implementthisusingifelsestatement andswitchstatement 6.DevelopaCprogramwhichaddsallnumbersfrom1toN,exceptthosewhichare divisibleby5.Implementthisusingforloopandcontinuestatement 7.DevelopaCprogramtofindfactorialofanumberNusingforloop 8.DevelopaCprogramtofindsumofalloddnumbersuptoNusingwhileloop 9.WriteaprogramtoprintASCIIvaluesofuppercaseandlowercasealphabetsand digits(AZ,azand09)

10.Writeaprogramtocalculaten!/(nr)!usingfunctions 11.WriteaProgramtofindifagivennumberisarmstrongnumber.(153=1^3+ 5^3+3^3) 12.Writeaprogramtodisplayallthevowelsinagivenlineoftext. 13.WriteamenubasedCprogramtoperformoperations(+,and*)onmatrices. 14.Writeaprogramtoreadyournameintoacharacterarray.Printthenamealong withthelengthofyournameandsizeofthearrayinwhichnameisstored. 15.Usescanffunctiontoreadastringofcharacters(intocharactertypearraycalled text)includingalphabets,digits,blanks,tabsetcexceptnewlinecharacter.Writea loopthatwillexamineeachcharacterinacharactertypearrayanddeterminehow manyofthecharactersareletters,howmanyaredigits,howmanyareblanksand howmanyaretabs.Assumethattextcontains80characters. 16.Generatethefollowingpyramidofnumbersusingnestedloops 1 212 32123 4321234 543212345 17.Writeaprogramtoreverseastringusingrecursivefunctions 18.Writearecursivefunctiontofindfactorialofanumber 19.Writeafunctiontoswapcontentsoftwovariablesusingfunctionsandpointer variables 20.Writeaprogramtosearchforanelementinagivenlistofelements.Usebreak statement 21.Developmultifileprogramtounderstandstatic,auto,register,global,staticglobal variables.Whatisthescopeandlifetimeofeachofthesetypesofvariables? 22.Writeaprogramtorepresenttimeofthedayinhrs,minsandsecs.Usestructures 23.Writeaprogramtoperformoperationsoncomplexnumbers. 24.Definestructurewithtwomembers(oneintandotherchar).Alsodefinesunion withtwomembers(oneintandotherchar).Printthesizesofstructureandunionin numberofbytes

25.ACprogramcontainsthefollowingdeclaration intx[8]={10,20,30,40,50,60,70,80}; a)Whatisthemeaningofx? b)Whatisthemeaningof(x+2)? c)Whatisthevalueof*x? d)Whatisthevalueof(*x+2)? e)Whatisthevalueof*(x+2)? 26.ACprogramcontainsthefollowingdeclaration floattable[2][3]={{1.1,1.2,1.3},{2.1,2.2,2.3}}; a)Whatisthemeaningofatable? b)Whatisthemeaningof(table+1)? c)Whatisthemeaningof*(table+1)? d)Whatisthemeaningof(*(table+1)+1)? e)Whatisthemeaningof(*(table)+1)? f)Whatisthevalueof*(*(table+1)+1)? g)Whatisthevalueof*(*(table)+1)? h)Whatisthevalueof*(*(table+1)? i)Whatisthevalueof*(*(table)+1)+1? 27.ACprogramcontainsthefollowingdeclaration char*color[6]={red,green,blue,white,black,yellow}; a)Whatisthemeaningofcolor? b)Whatisthemeaningof(color+2); c)Whatisthevalueof*color? d)Whatisthevalueof*(color+2)? e)Howdocolor[5]and*(color+5)differ? 28.Write a program to read n number of strings using twodimensional character array,sortthemanddisplaythesortedlistofstringsonthescreen. 29.Writeaprogramtoreadnnumberofstringsanddisplaythemonthescreen.Use arrayofpointersanddynamicmemoryallocationtechniques 30. WriteaCprogramwithafunctionany(s1,s2).Thisfunctionreturnsthefirst location (index of location) in the string s1 which matches with any string in s2 otherwise 31.Write a C program with a function delete (s1, c). This function deletes each characterins1whichmatchescharacterc

32. WriteaCprogramwithafunctiondeletes2(s1,s2).Thisfunctiondeleteseach characterinstrings1whichmatchesanycharacterinstrings2 33. Writea C program with a function rotoate_right (n, b). This function rotates integerntowardsrightbybpositions 34.WriteaCprogramwithafunctioninvertponwards(n,p,b).Thisfunctioninverts bbitsofintegern,thatbeginatpositionp,leavingtheothersunchanged 35.WriteaCprogramwithafunctiont olower,whichconvertsuppercaselettersto lowercase.Useconditionalexpression 36. Experimenttofindoutwhathappenswhenprintfargumentstringcontains\x, wherexissomecharacter(a,b,c,\,^etc).Whatareyourobservations 37.Writeafunctionexpand(s,t)whichconvertscharacterslikenewlineandtabinto visible escape sequences like \n and \t as it copies the string s to t. Use switch statementandalsodisplaybothsandtattheend 38.Writeafunctionexpand(s1,s2)whichexpandsshorthandnotationsofs1likead intoabcdand09to0123456789ins2.Forexampleifthestringins1is0123ae14 thens1isexpandedins2to0123abcde1234 39.WriteaCprogramwithtwofunctionsitob(n,s)anditoh(n,s).itobconverts integerintobinarycharacterrepresentationins.Similarlyitohconvertsintegerinto hexadecimalcharacterrepresentationins. 40.WriteaCprogramwithafunctionindexr(s,t),whichreturnstheindexofright mostoccurrenceoftinsotherwise1 41.WriteaCprogramwitharecursivefunctionreverse(s),whichreversesthestrings 42.WriteaCprogramwitharecursivefunctionitoa,whichconvertsintegerintoa string 43.WriteaProgramtoimplementstrtoklibraryfunction. 44.Writeaprogramtoaddfirstseventermsofthefollowingseries: 1/1!+2/2!3/3!+4/4!... 45.Writeaprogramthatwillconcatenatetwofiles,thatisappendthecontentsofone fileattheendofanotherfileandwritetheresultsintoathirdfile.Youmustbeable toexecutecommandatDOSpromptasfollows:

C>CONCATSource1.txtsource2.txtTarget.txt 46.Writeaprogramtoprintoutallrotationsofastringtypedin.Foreg:iftheinputis Space,theoutputshouldbe:spacepacesacespcespaespac 47.Implementstringlibraryfunctions.strrev,strcpy,strcat,strcmpwithsamereturn valuesandallerrorhandlingfeaturesusingpointers 48.WriteaprogramtocomputefactorialandGCDusingrecursion. 49.Writeamenudrivenapplicationthatperformsthefunctionsofacalculator.The inputsfromtheusershouldbevalidatedanderrormessagesincase,inputsarenot valid,shouldbedisplayedofmultiplication,division,factorials(userecursion)and squares.Modularizethecodewhereverpossible. 50.Writeaprogramtofindoutdifferenceindaysbetweenanytwodates.Itmust workregardlessoftheyear,monthandday.ConsiderLeapyearswhilecalculating thedifference. 51.Writeaprogramtocountthenumberofeinthefollowingarrayofpointertothe string. char*s[]={ wewillteachyouhowto; Moveamountain; Levelabuilding; Erasethepast; Makeamillion; } 52.Write a program in which define a as an unsigned integer whose value is (hexadecimal) 0xa2c3. Write the corresponding bit pattern for this value. Then evaluate each of the following bitwise expressions, first showing the resulting bit patternandthentheequivalenthexadecimalvalue.Utilizetheoriginalvalueofain eachexpression.Assumethataisstoredina16bitword a)~a b)a^0x3f06 c)a|0x3f06 d)a|~0x3f06 e)a>>3 f)a<<5 g)a^~a h)a|~a i)(a&~0x3f06)<<8 j)a&~(0x3f06>>8)

53.Defineastructuredeclarationforeachofthefollowingsituations.Assumea16bit integerword a)Definethreebitfields,calleda,bandc,whosewidthsare6bits,4bitsand6 bits,respectively b)Declareastructuretypevariablevhavingthecompositiondefinedinpart(a) above.Assigninitialvalues3,5and7respectively,tothethreebitfields.Arethe bitfieldslargeenoughtoaccommodatethesevalues? c)Whatarethelargestvaluesthatcanbeassignedtoeachofthebitfieldsdefined inpart(a)above? d)Definethreebitfields,calleda,bandc,whosewidthsare8bits,6bitsand5 bits,respectively.Howwillthesefieldsbestoredwithinthecomputersmemory? e)Definethreebitfields,calleda,bandc,whosewidthsare8bits,6bitsand5 bitsrespectively.Separateaandbwith2vacantbits 54.Write a C program that will accept a hexadecimal number as input, and then displayamenuthatwillpermitanyofthefollowingoperationstobecarriedout a)Displaythehexadecimalequivalentoftheonescomplement b)Carryoutamaskingoperationandthendisplaythehexadecimalequivalentof theresult c)Carryoutabitshiftingoperationandthendisplaythehexadecimalequivalentof theresult d)Exit 55.WriteaCprogramthatwillillustratetheequivalencebetween a)Shiftingabinarynumbertotheleftnbitsandmultiplyingthebinarynumber by2n b)Shiftingabinarynumbertotherightnbitsanddividingthebinarynumber by2n. Choosetheinitialbinarynumbercarefully,sothatbitswillnotbelostasaresult oftheshiftingoperation 56.Defineacharacterarrayofsize35(35bytes)tostore40characters.Todosouse thebitwiseshiftoperatorsinsuchamannerthatagroupofeightcharactersisstored insevenconsecutivearrayelements.Eacharrayelementwillcontainonecomplete character, plus one bit from another character. Include a provision to display the contentsofthe35bytearrayincompressedformandintheequivalentform 57.Write a program to display a number in different number systems. Begin by displayingamenuthatallowstheusertospecifythattypeofnumber(i.ethedesired numbersystem)beforeenteringtheactualvalue.Thendisplaytheinputintheother twonumbersystemsandintermsofitsequivalentbinarybitpattern

58.WriteaCprogramtocalculatefactorialofanumber.Factorialfunctionhastobe writtenasamultilinemacro 59.WriteaprogramtosearchforagivenelementinalistofelementsusingLinear Search. Use flag to represent the status of search. Define flag as an enumeration variablewhosevalueiseithertrueorfalse 60.WriteamenudrivenCprogramtoperformoperationsonComplexnumbers.Use enumerationdatatypetoidentifythedifferentoperationsonComplexnumbers 61.WriteaCprogramtoopenafileandstoretext(charactertypedata)inones complementform.Readthecontentsfromthefileanddisplayasitisaswellinones complementform.UsecommandlineargumentstopassfilenametoyourCprogram 62.WriteaprogramtoembedassemblylanguagecodeinCprogram 63.Develop sample programs using preprocessor operators #, ## and also conditionalcompilation 64.DevelopaprogramtogeneratemarkssheetofCDACStudents(DSSD,DESDand DACcourses).Modulesaredifferentforeachcourse.Implementthisusingstructures, unions,arrays,loopsandvariables 65.Writeaprogramwhichreadsalineofcharacters.Eachcharacterenteredfromthe keyboard is tested to determine its case, and is then written to the data file in oppositecase.Displaythecontentsofthefile.Alsouseftellandfseektodetermine thecurrentfilepositionandtochangethefileposition 66.Writeaninteractive,fileorientedCprogramthatwillmaintainalistofnames, addressesandtelephonenumbersinalphabeticalorder(bylastnames).Processthe informationassociatedwitheachnameasaseparaterecord,representeachrecordas astructure.Includeamenuthatwillallowtheusertoselectanyofthefollowing features: a)Addanewrecord b)Deletearecord c)Modifyanexistingrecord d)Retrieveanddisplayanentirerecordforagivenname e)Generateacompletelistofallnames,addressesandtelephonenumbers f)Endthecomputation Besuretorearrangetherecordswheneveranewrecordisaddedorarecordis deleted,sothattherecordsarealwaysmaintainedinalphabeticalorder.Utilizea linearlinkedlist.Alsouseftellandfseekwhereverrequired

67.Writeaprogramthatwillgenerateadatafilecontainingalistofcountriesand their corresponding capitals. Write interactive code which will access the above createddatafiletoperformthefollowingoperations a)Determinethecapitalofaspecifiedcountry b)Determinethecountrywhosecapitalisspecified c)Terminatetheprogramme

Anda mungkin juga menyukai