好文档就是一把金锄头!
欢迎来到金锄头文库![会员中心]
电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

C语言学习第六章(英文版).ppt

81页
  • 卖家[上传人]:清晨86****784
  • 文档编号:290323149
  • 上传时间:2022-05-09
  • 文档格式:PPT
  • 文档大小:1.10MB
  • / 81 举报 版权申诉 马上下载
  • 文本预览
  • 下载提示
  • 常见问题
    • Chapter 6 Arraysschool of Software, Nanchang HangKong University 6 ArraysChapter 6 ArraysChapter 6 Arraysschool of Software, Nanchang HangKong University WhatareArraysn6.2 OneDimensionalArrayn6.3 DeclaringArrayn6.4 ArrayInitialisationandSubscriptingn6.5 ExamplesUsingOneDimensionalArrayn6.6 Passing1-DArraytoaFunctionn6.7 TwoDimensionalArrayn6.8 Initialisinga2-DArrayn6.9 ExamplesUsingTwoDimensionalArrayn6.10Passing2-DArraytoaFunctionOutlineOutlineChapter 6 Arraysschool of Software, Nanchang HangKong University PointsKey PointsChapter 6 Arraysschool of Software, Nanchang HangKong University void main()int mark1,mark2,mark3,mark4,mark5;int mark6,mark7,mark8,mark9,mark10;int sum;float aver;printf(“please input ten marks”):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(“the total and average marks are %d,%f”,sum,aver);Thinkaboutthisquestion:Input those marks obtained by 10 students in a test, write a program to find the average and total marks. Isthattroublesome?Howabout50students?Any better way to solve it ?Chapter 6 Arraysschool of Software, Nanchang HangKong University What are Arrays6.1 What are Arraysn编程用数组实现上例。

      编程用数组实现上例n编程统计编程统计6位候选人的选票位候选人的选票n编程用数组记录编程用数组记录50个随机数,并输出个随机数,并输出Chapter 6 Arraysschool of Software, Nanchang HangKong University What are Arrays6.1 What are ArraysnArraysnStructuresofrelateddataitemsnStaticentitysamesizethroughoutprogramnDynamicdatastructuresdiscussedinotherchapterChapter 6 Arraysschool of Software, Nanchang HangKong University What are Arrays6.1 What are ArraysnTheClanguageprovidesacapabilitythatenablestheusertodesignasetofsimilardatatypes,calledarray.nOrdinaryvariablescanonlyholdonevalueatatime,however,anarraycanstoremorethanonevalueatatime.nAnarrayisacollectivenamegiventoagroupofsimilarquantities.Chapter 6 Arraysschool of Software, Nanchang HangKong University What are Arrays6.1 What are ArraysnAnarrayisacollectionofsimilarelements.Thesesimilarelementscouldbeallints,orfloats,orcharsetc.nForexample,assumethefollowinggroupofnumbersrepresentmarksobtainedbyfivestudents.nper=48,88,34,23,96nIfwerefertothesecondnumberofthegroup,theusualnotationusedisper2.InC,thesecondnumberisreferredasper1.Thecountingofelementsbeginwith0,not1Chapter 6 Arraysschool of Software, Nanchang HangKong University One Dimensional Array6.2 One Dimensional ArraynArraynGroupofconsecutivememorylocationsnAblockofmanyvariablesofthesametype、SamenamencanbedeclaredforanytypenExamplesnlistofstudentsmarksnseriesofnumbersenteredbyusernVectorsnmatricesnTorefertoanelement,specifynArraynamenPositionnumbernFormat:arraynamepositionnumbernFirstelementatposition0nnelementarraynamedc:nc0,1Nameofarray(Notethatallelementsofthisarrayhavethesamename,c)Positionnumberoftheelementwithinarraycc6-4560721543-89062-31645378c0c1c2c3c11c10c9c8c7c5c4Chapter 6 Arraysschool of Software, Nanchang HangKong University One Dimensional Array6.2 One Dimensional ArraynArrayelementsarelikenormalvariablesc0=3;printf(%d,c0);nPerformoperationsinsubscript.Ifxequals3c5-2=c3=cxChapter 6 Arraysschool of Software, Nanchang HangKong University Declaring array 6.3 Declaring array nWhendeclaringarrays,specifynNamenTypeofarraynNumberofelementsnarrayTypearrayNamenumberOfElements;nExamples:nintc10;nfloatmyArray3284;nDeclaringmultiplearraysofsametypenFormatsimilartoregularvariablesnExample:nintb100,x27;Chapter 6 Arraysschool of Software, Nanchang HangKong University Array 6.4 Array InitialisationInitialisation and Subscripting and SubscriptingnArrayInitialisationnintn5=1,2,3,4,5;nIfnotenoughinitializers,rightmostelementsbecome0nintn5=0nIftoomany,asyntaxerrorisproducednCarrayshavenoboundscheckingnIfsizeomitted,initializersdetermineitnintn=1,2,3,4,5;n5initializers,therefore5elementarrayChapter 6 Arraysschool of Software, Nanchang HangKong University Array 6.4 Array InitialisationInitialisation and Subscripting and SubscriptingnIfaisanarray,wecanwriteaexpr,whereexprisanintegralexpression,toaccessanelementofthearray.nWecallexprasubscript,orindexofa.nTheexpressionaicanbemadetorefertoanyelementofthearraybyassignmentofanappropriatevaluetothesubscripti.neg.ai+j,ai-j,ai+2Chapter 6 Arraysschool of Software, Nanchang HangKong University Array 6.4 Array InitialisationInitialisation and Subscripting and Subscripting#include void main()int n 5 = 1, 2, 3, 4, 5 ;int m5,i;for(i=0;i4;i+)mi=ni;for(i=0;i5/2;i+)n4-i=ni;for(i=0;i4;i+)printf(“%d %dn”,mi,ni);refer to the element of array m by mirefer to the element of array n by ni,n4-iChapter 6 Arraysschool of Software, Nanchang HangKong University Array 6.4 Array InitialisationInitialisation and Subscripting and SubscriptingnAsinglearrayelementaiisaccessedwhenihasavaluegreaterthanorequalto0andlessthanorequaltoN1.nIfihasavalueoutsidethisrange,arun-timeerrorwilloccurwhenaiisaccessed.nOverrunningtheboundsofanarrayisacommonprogrammingerror.Chapter 6 Arraysschool of Sof。

      点击阅读更多内容
      关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
      手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
      ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.