问题描述
(Questionsmarked*areforextrapracticeanddonotneedtobedemonstratedtothelecturer.)(Youonlyneedtosavethe.cppfileforeachquestion.Ifyoumakeanewprojectforeachprogram,youwillrunoutofspace.Thereforeyoumusteitherdeletealltheotherfilesorhaveoneprojectandreplacethe.cppfileeachtime.)LECTURE2:11.Writeaprogramcontainingthefollowingcodeandthenmodifyitsothatitalsoprintsthesquareofn-1.12.Modifyyourprogramfromquestion11touseaforlooptoachieveexactlythesamefunctionality.13.Modifyyourprogramfromquestion11touseadowhilelooptoachieveexactlythesamefunctionality.Whathappensifthefirstnumberenteredis0?14.Writeandrunaprogramthatreadsapositiveintegernandthenprintsatriangleofasterisksinthatnumberofrows.Useaforloop.Forexample,ifnis4,thentheoutputwouldbe:**********14*.Canyoumodifyyourcodefromquestion14todisplayadiamond?E.g.forsize3theoutputwouldbe:*************15.Usethedebuggertostepthroughyourcodefromquestion14.Noticehowthecodeintheloopisrepeatedandwatchthechangingvalueofthevariablecontrollingtheloop(seeWatchwindow).Findouthowtosetabreakpointandruntheprogramtostopatthebreakpoint.Canyoualsoruntocursor?16.Writeandtestafunctionvoidtriangle(intn)tooutputatriangleofasterisks(asinquestion15).16*.Canyoumodifythefunctionfromquestion16topassacharacterasaparameteraswell?17.Writeandtestafunctionthatreturnstheareaofacirclewithgivenradius.Thefunctionshouldhavethefollowingprototype:floatarea(floatr)18.Writeandtestafunctionthatdetermineswhetheragivenintegerisaprimenumber.(Thenumbernisprimeifitisnotdivisiblebyanyintegergreaterthan1andlessthann.)Thefunctionshouldreturn1ifthenumberisprimeand0otherwise.Thefunctionprototypeshouldbeasfollows:intisPrime(intn)(N.B.Thefirsttenprimenumbersare2,3,5,7,11,13,17,19,23and29.)19.Writeandtestafunctionthatreturnstheareaaandcircumferencecofacirclewithgivenradiusr.Thefunctionshouldhavetheprototype:voidcomputeCircle(float&a,float&c,floatr)20.Writeandrunaprogramthatreadsinintegersintoanarrayinreverseandthendisplaysthemintheorderthattheyarestored.Forexample,thefirstnumberreadinisstoredinthelastpositionandisdisplayedlast.21.Writeandtestafunctionthatreplacesallthenegativenumbersinanarrayofintegerswiththeirabsolutevalues.Yourfunctionmustworkforarraysofdifferentsizes.22.Writeandtestafunctionthatreturnstheminimumvaluestoredinanarray.Modifyyourfunctionsothatitalsoreturnstheindexoftheminimumvaluestoredinanarray.23.Writeandtestthefollowingfunctionthatattemptstoremoveanitemfromanarray:intremove(inta[],int&n,intx)Thefunctionsearchesthefirstnelementsofthearrayafortheitemx.Ifxisfound,itisremoved,alltheelementsabovethatpositionareshifteddown,nisdecremented,and1isreturnedtoindicateasuccessfulremoval.Ifxisnotfound,thearrayisleftunchangedand0isreturnedtoindicate“failure”.23*.Modifythefunctionfromquestion23toremovealloccurrencesofxinthearrayandthenreturnthetotalnumberofelementsremoved.Isitdoingitthemostefficientway?
解决方案
解决方案二:
人家叫你用c语言写