版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、3414_E01.zip文件和邮件名相同压缩包内文件无所谓命名在下周二上课前交Exercise1:ProgrammingEnvironmentandBasicInput/OutputWriteaptogramthatpnnts,Tliisismyfirstprogiam!”onthescreen.l.Savethisprogramontoyourowndiskwiththenameofe2-la;(a)RunthisprogramwithoutopeningTurboC;(b)Modifythisprogramtoprint,Tliisismysecondprogram!M,thensavei
2、tas(c)e2-lb.Pleasedonotoverwritethefirstprogiam.Writeaprogramthatprintsthenumber1to4onthesameline.Writetheprogram2.usingthefbllowingmethods:Usingfour“printf“statements.(a)(i.e.no'%)Usingone,printf"statementwithnoconversionspecifier(b)Usingone“printf''statementwithfourconversionspeci
3、fiers(c)(a)Writeaprogiamthatcalculatesanddisplaysthenumberofminutesin15days.3minuteshours180anddisplayshowmanyprogram(b)Writeathatcalculatesequalto.(c) (Optional)Howabout174minutes?Exercise2:DataTypesandArithmeticOperations1 .Youpurchasealaptopcomputerfor$889,Thesalestaxrateis6percent.Writeandexecut
4、eaCprogiamthatcalculatesanddisplaysthetotalpurchaseprice(netpricesalestax).printsthecircle'sdiameter,Writeaprogramthatreadsintheradiusofacircleand2 .“value3.14159for"?cii'cumfei'enceandarea.Usetheamnialandbalanceannumbers:thatprogramreadsintwoanaccounta.3Writeinterestrateexpressedas
5、apercentage.Ybiu,progiamshouldthendisplaythenewjusttheinterestpayment.一balanceafterayear.TlierearenodepositsorwithdiawsYburprogramshouldbeabletoreproducethefollowingsamplerun:Interestcalculationprogram.Startingbalance?60004.25Annualinterestratepercentage?Balanceafteroneyear:6255.00Exercise3:Selectio
6、nstructure1.WriteaCprogi'amthatacceptsastudent'snumericalgrade,convertsthenumericalgradetoPassed(gradeisbetween60-100),Failed(gi,adeisbetween0-59),orEiTor(gradeislessthan0orgreaterthan100).Writeaprogramthataskstheusertoenteranintegernumbei;thentellsthe.2userwhetheritisanoddorevennumber.Write
7、aprogiamthatreadsinthreeintegersandthendetenninesandprintsthe3largestinthegroup.Exercise4:"switch1statementandsimple“while”repetitionstatement1. Writeaprogramthatreadsthreeintegersanabbreviateddate(forexample:261294)andthatwillprintthedatemftill:forexample:26thDecember1994.Thedayshouldbefollowe
8、dbyanappropriatesuffix,'st',*nd'rd'or'th'.Useatleastonesvzitchstatement.2. WriteaCprogramthatusesawhilelooptocalculateandprintthesumoftheevenintegersfrom2to30.3. Alargechemicalcompanypaysitssalesstaffonacommissionbasis.Theyreceive£200perweekplus9%oftheirgrosssalesforthat
9、week.Forexample,someonewhosells£5000ofchemicalsinoneweekwillearn£200plus9%of£5000,atotalof£650.DevelopaCprogramthatwillinputeachsalesperson'ssalesforthepreviousweek,andprintouttheirsalary.Processoneperson'sfiguresatatime.Enter sales in pounds(-1 to end) : 5000.00Salaryis:
10、650.00Enter sales in pounds(-1 to end) : 00.00Salaryis:200.00Enter sales in pounds(-1 to end): 1088.89Salaryis:298.00Enter sales in pounds(-1 to end): -1Optional:两重的while4. Amailordercompanyselkfivedifferentproductswhoseretailpricesareshowninthefollowingtable:ProductNumberRetailPrice(inpounds)1 2.98
11、2 4.503 9.984 4.495 6.87WriteaCprogramthatreadsinaseriesofpairsofnumbersasfollows:(1) .Productnumber(2) .QuantitysoldforonedayYourprogramshoulduseaswitchstatementtohelpdeterminetheretailpriceforeachproduct,andshoulduseasentinel-controlledlooptocalculatethetotalretailvalueofallproductssoldinagivenwee
12、k(7days).Exercise5:'for1and'dowhile“repetitionstatements1. Writeaprogramwhichusesado/whilelooptoprintoutthefirst10powersof2otherthan1210).Useafor,20(ie.itprintsoutthevaluesof2looptodothesame.,22. Theconstant?canbecalculatedbytheinfiniteseries:4/3+4/5-4/7+4/9-4/11+.WriteaCprogramtliatusesado/
13、whilelooptocalculate?usingtheseries.Theprogramshouldasktheuserhowmanytermsintheseriesshouldbeused.Thusiftheuserenters'3thentheprogramshouldcalculate?asbeing4-4/3+4/5.Nestedrepetition3. Writeaprogramthatprintsthefollowingdiamondshape.Youmayuseprintfstatementsthatprinteitherasingleasterisk(*)orasi
14、ngleblank.Maximizeyouruseofrepetition(withnestedforstatements)andminimizethenumberofprintfstatements.*4. Writeaprogi-amtopnntatableasfollows:1*1=12*1=22*2=43*1=33*2=63*3=9*9*1=99*2=189*3=279*4=369*5=459*6=549*7=639*8=729*9=81Exercise6:SimpleFunctions1. WriteaCprogramthatreadsseveralnumbersandusesthe
15、fimctionround_to_nearesttoroundeachofthesenumberstothenearestinteger.Theprogramshouldprintboththeoriginalnumberandtheroundednumber.2. Writeaprogramthatreadsthreepairsofnumbersandaddsthelargerofthefirstpair,thelargerofthesecondpairandthelargerofthethirdpair.Useafunctiontoreturnthelargerofeachpair.3.
16、Acarparkchargesa£2.00minimumfeetoparkforupto3hours,andanadditional£0.50foreachhourorparthourmexcessoftlireehours.Themaximumchargeforanygiven24-liourperiodis£10.00.Assumethatnocarparksformorethan24hoursatatime.WriteaCprogramtliatwillcalculateandprinttheparkingcliargesforeachof3customer
17、swhoparkedtheircarinthecarparkyesterday.Theprogramshouldacceptasinputthenumberofhoursthateachcustomerhasparked,andoutputtheresultsinaneattabularform,alongwiththetotalreceiptsfromthethreecustomers:CarHoursCharge11.52.002.504.02324.010.00TOTAL29.514.50Theprogramshouldusetheftmctioncalculate_chargestod
18、eterminethechargeforeachcustomer.Exercise7:MoreFunctions1. Writeaprogramthatusessentinel-controlledrepetitiontotakeanintegerasinput,andpassesittoafunctionevenwhichusesthemodulusoperatortodetermineiftheintegeriseven.Theftuictionevenshouldreturn1iftheintegeriseven,and0ifitisnot.Theprogramshouldtakethe
19、valuereturnedbytheftmctionevenanduseittoprintoutamessageannouncingwhetherornottheintegerwaseven.2. WriteaCprogramthatusesthefunctionintegerPowerl(base,exponent)toreturnthevalueof:exponentbasesothat,forexample,integerPowerl(3Z4)givesthevalue3*3*3*3.Assumethatexponentisapositive,non-zerointeger,andbas
20、eisaninteger.Thefunctionshoulduseaforloop,andmakenocallstoanymathlibraryfunctions.3. WriteaCprogramthatusestherecursiveftmctionintegerPower2(base,exponent)toretunithevalueof:exponentbasesothat,forexample,integerPower2(3,4)givesthevalue3*3*3*3.Assumethatexponentisapositive,non-zerointeger,andbaseisan
21、integer.Thefunctionshouldmakenocallstoanymathlibraryfimctions.(Hint:therecursivestepwillusetherelationship:exponent-1exponent=base.basebase1andthebasecasewillbewhenexponentis1since:base=base.)Exercise8:Arrays1. Writeaprogramthatreadstennumberssuppliedbytheuserintoasinglesubscriptedarray,andthenprint
22、souttheaverageofthem.2. Writeaprogramthatreadstennumberssuppliedbytheuserintoa2by5array,andthenprintsoutthemaximumandminimumvaluesheldin:(a) eachrow(2rows)(b) thewholearray3. Useasingle-subscriptedarraytosolvethefollowingproblem.Readin20numbers,eachofwhichisbetween10and100.mchisive.Aseachnumberisrea
23、d,printitonlyifitisnotaduplicateofanumberalreadyread.Prepareforthe"worstcase''inwhichall20numbersaredifferent.Usethesmallestpossiblearraytosolvethisproblem.Exercise9:MoreArrays1. Writeaprogramthatenters5namesoftownsandtheirrespectivedistance(aninteger)fromLondoninmiles.Theprogramwillpri
24、ntofthenamesofthetownsthatarelessthan100milesfromLondon.Usearraysandcharacterstringstoimplementyourprogram.2. Writeaprogramthatpronq)tstheusertotypeinfourcharacterstrings,placestheseinanarrayofstrings,andthenprintsout:(eg.IamPeterPan)(i) Thefourstringsinreverseorder.(e.g.PanPeteramI)(ii) Thefourstri
25、ngsintheoriginalorder、butwitheachstringbackwards.(eg.ImaretePnaP)(iii) Thefourstringsinreverseorderwitheachstringbackwards.(e.g.naPretePmaI)Exercise10:PointersWriteaprogiamthatreads5integersintoanarray,andthenusesfourdifferent1.methodsofaccessingthemembersofananaytoprintthemoutinteveiseorder.2. Writeaprogi'amthatreads8floatsintoanaiTayandthenprintsoutthesecond,fourth,sixthandeighthmembersofthearray,andthesumofthefirst,tliird,fifthandseventh,usingpointerstoaccessthememberso
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 妇科肿瘤手术中的代谢免疫调控策略
- 妇科恶性肿瘤靶向免疫联合治疗的优化方案
- 女职工职业健康监护特殊规范与实操
- 大数据驱动的库存周转优化策略
- 大数据在应急物资调度中的应用
- 台词考试诗词大全及答案
- 2025年中职(制冷和空调设备运行与维护)制冷系统安装测试题及答案
- 2025年中职国土资源调查与管理(测量实操)试题及答案
- 2026年绿色租赁创新模式项目评估报告
- 2025年中职包装设计(包装基础设计)试题及答案
- 器官移植术后排斥反应的风险分层管理
- 护坡绿化劳务合同范本
- 临床绩效的DRG与CMI双指标调控
- 2026年湛江日报社公开招聘事业编制工作人员备考题库及完整答案详解
- 2025-2026学年人教版数学三年级上学期期末仿真模拟试卷一(含答案)
- 2025年凉山教师业务素质测试题及答案
- 企业尽职调查内容提纲-中英文对照
- GB/T 18997.1-2020铝塑复合压力管第1部分:铝管搭接焊式铝塑管
- 物料提升机保养记录表
- 方志文献《兖州府志》
- 光伏电源项目工程建设管理资料表格格式汇编
评论
0/150
提交评论