资源描述:
《C语言学习第六章(英文版)课件.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Chapter6Arrays6.1WhatareArrays6.2OneDimensionalArray6.3DeclaringArray6.4ArrayInitialisationandSubscripting6.5ExamplesUsingOneDimensionalArray6.6Passing1-DArraytoaFunction6.7TwoDimensionalArray6.8Initialisinga2-DArray6.9ExamplesUsingTwoDimensionalArray6.10Passing2-DArraytoaFunctionOutlineOneDimensi
2、onalArrayDeclaringArrayArrayInitialisationandSubscriptingExamplesUsingOneDimensionalArrayPassing1-DArraytoaFunctionTwoDimensionalArrayInitialisinga2-DArrayExamplesUsingTwoDimensionalArrayPassing2-DArraytoaFunctionKeyPoints#includevoidmain(){intmark1,mark2,mark3,mark4,mark5;intmark6,mark7,
3、mark8,mark9,mark10;intsum;floataver;printf(“pleaseinputtenmarks”):scanf(“%d,%d,%d,%d,%d”,&mark1,&mark2,&mark3,&mark4,&mark5);scanf(“%d,%d,%d,%d,%d”,&mark6,&mark7,&mark8,&mark9,&mark10);sum=mark1+mark2+mark3+mark4+mark5+mark6+mark7+mark8+mark9+mark10;aver=sum/10.0;printf(“thetotalandaveragemarksare
4、%d,%f”,sum,aver);}Thinkaboutthisquestion:Inputthosemarksobtainedby10studentsinatest,writeaprogramtofindtheaverageandtotalmarks.Isthattroublesome?Howabout50students?Anybetterwaytosolveit?6.1WhatareArrays编程用数组实现上例。编程统计6位候选人的选票。编程用数组记录50个随机数,并输出。6.1WhatareArraysArraysStructuresofrelateddataitemsStati
5、centity–samesizethroughoutprogramDynamicdatastructuresdiscussedinotherchapter6.1WhatareArraysTheClanguageprovidesacapabilitythatenablestheusertodesignasetofsimilardatatypes,calledarray.Ordinaryvariablescanonlyholdonevalueatatime,however,anarraycanstoremorethanonevalueatatime.Anarrayisacollectivena
6、megiventoagroupof‘similarquantities’.6.1WhatareArraysAnarrayisacollectionofsimilarelements.Thesesimilarelementscouldbeallints,orfloats,orcharsetc.Forexample,assumethefollowinggroupofnumbersrepresentmarksobtainedbyfivestudents.per={48,88,34,23,96}Ifwerefertothesecondnumberofthegroup,theusualnotatio
7、nusedisper2.InC,thesecondnumberisreferredasper[1].Thecountingofelementsbeginwith0,not16.2OneDimensionalArrayArrayGroupofconsecutivememorylocationsAblockofmanyvariablesofthesametype、Samenamecanbedeclaredforanytype