川北医学院:《C++程序设计》课程教学资源(课件讲稿)第5章 数组 Arrays

第5章数组(Arrays) 5.1数组的概念 5.2一维数组的定义和引用 5.3二维数组的定义和引用 5.4用数组名作函数参数 5.5字符数组 *5.6C++处理字符串的方法一字符串类与字 符串变量 2017年4月26日12时17分 2 HOM正 第5章数组 BACK NEXT
HOME2017年4月26日12时17分 第5章 数组 2 5.1 数组的概念 5.2 一维数组的定义和引用 5.3 二维数组的定义和引用 5.4 用数组名作函数参数 5.5 字符数组 *5.6 C++处理字符串的方法——字符串类与字 符串变量

Definition Array is an aggregation including a certain sequential and same type variables.These variables are called elements of the array which have the same data type. Array belongs to tectonic type,and can represent each element exclusively with uniform array name and subscript. 017年4月26日12时17分 HOME 第5章数组 3 BACK NEX
HOME2017年4月26日12时17分 第5章 数组 3 Array is an aggregation including a certain sequential and same type variables. These variables are called elements of the array which have the same data type. Array belongs to tectonic type, and can represent each element exclusively with uniform array name and subscript

Declaration and Reference of 1-dimension array Declaration 类型标识符 数组名[常量表达式]; For example:int a[10]; -“a”is an integer array with ten elements of a[o]to a[9] Reference 数组名[下标] Declared firstly then used and only can be reference one by one. 017年4月26日12时17分 HOME 第5章数组 BACK NEX
HOME2017年4月26日12时17分 第5章 数组 4 • Declaration • 类型标识符 数组名 [常量表达式]; • For example: int a[10]; – “a” is an integer array with ten elements of a[0] to a[9] • Reference • 数组名[下标] – Declared firstly then used , and only can be reference one by one

Storage order of 1-dimension array Array elements are stored in succession, and their address is continuous. For example: a a[0]a[1]a[2]a[3] a[4] a[5]a[6]a[7] a[8]a[9] Note:Array name is memory address of the first array element,so it is a constant and can't be valuated. C++does not allow the dynamic definition of the array size 017年4月26日12时17分 第5章数组 5 HOM BACK NEX
HOME2017年4月26日12时17分 第5章 数组 5 Array elements are stored in succession, and their address is continuous. For example: Note: Array name is memory address of the first array element, so it is a constant and can’t be valuated. C + + does not allow the dynamic definition of the array size . a a[0] a[1] a[2] a[3] a[4] a[5] a[6] a[7] a[8] a[9]

例5.1数组元素的引用 #include using namespace std; int main() { int i,a[10]; for(=0;i=0;i-) cout<<a[叮<<""; cout<<endl; return 0; 2017年4月26日12时17分 6 HOM正 第5章数组 BACK NEXT
HOME2017年4月26日12时17分 第5章 数组 6 #include using namespace std; int main( ) { int i,a[10]; for (i=0;i=0;i--) cout<<a[i]<<" "; cout<<endl; return 0; }

oInitialization of 1-dimension array Evaluate the array elements with initial value while declaring the array. For example:static int a[10]={0,1,2,3,4,5,6,7,8,9); Evaluate some of the array elements with initial value. For example:static int a[10]={0,1,2,3,4); The length of the array may not be specified while evaluating all the elements of the array. For example:static int a[]={1,2,3,4,5); 2017年4月26日12时17分 7 HOM 第5章数组 BACK NEXT
HOME2017年4月26日12时17分 第5章 数组 7 – Evaluate the array elements with initial value while declaring the array. For example:static int a[10]={0,1,2,3,4,5,6,7,8,9}; – Evaluate some of the array elements with initial value. For example:static int a[10]={0,1,2,3,4}; – The length of the array may not be specified while evaluating all the elements of the array. For example:static int a[ ]={1,2,3,4,5};

oInitialization of 1-dimension array Can not evaluate the array as a whole Global and static array's default value is 0 017年4月26日12时17分 8 HOME 第5章数组 BACK NEXT
HOME2017年4月26日12时17分 第5章 数组 8 – Can not evaluate the array as a whole – Global and static array’s default value is 0

5.2.4一维数组程序举例 例5.2用数组来处理求例3.13 Fibonacci数列问题。 这是一个有趣的古典数学问题:有一对兔子,从出生后第3个 月起每个月都生一对兔子。小兔子长到第3个月后每个月又生 一对兔子。假设所有兔子都不死,问每个月的兔子总数为多 少? 这个数列有如下特点:第1、2个数为1、1。从第3个数开始, 每个数是其前面两个数之和。即 F1=1 (n=1) F2=1 (n=2) Fn=Fn-1+Fn-2 (n23) 可以用20个元素代表数列中的20个数,从第3个数开始,可 以直接用表达式 f叮=fi-2]+fi-1]求出各数。 2017年4月26日12时17分 第5章数组 BACK NEX
HOME2017年4月26日12时17分 第5章 数组 9 例5.2 用数组来处理求例3.13 Fibonacci数列问题。 这是一个有趣的古典数学问题:有一对兔子,从出生后第3个 月起每个月都生一对兔子。小兔子长到第3个月后每个月又生 一对兔子。假设所有兔子都不死,问每个月的兔子总数为多 少? 这个数列有如下特点:第1、2个数为1、1。从第3个数开始, 每个数是其前面两个数之和。即 F1=1 (n=1) F2=1 (n=2) Fn=Fn-1+Fn-2 (n≥3) 可以用20个元素代表数列中的20个数,从第3个数开始,可 以直接用表达式 f[i]=f[i-2]+f[i-1]求出各数

#include #include using namespace std; int main() long f1,f2; int i; f1=f2=1; for(i=1;i<=20;it+) cout<<setw(12)<<f1<<setw(12)<<f2; if(i%2==0)cout<<endl; f1=f1+f2; f2=f2+f1; } return 0; 2017年4月26日12时17分 HOM正 第5章数组 10 BACK NEXT
HOME2017年4月26日12时17分 第5章 数组 10 #include #include using namespace std; int main( ) { long f1,f2; int i; f1=f2=1; for(i=1;i<=20;i++) { cout<<setw(12)<<f1<<setw(12)<<f2; if(i%2==0) cout<<endl; f1=f1+f2; f2=f2+f1; } return 0; }

#include #include using namespace std; int main() {inti,f20]={1,1; for(i=2;i<20;i++) f[0=f[i-2]+fi-1]; for(i=0;i<20;i++) if(i%5==0)cout<<endl; cout<<setw(8)<<f[i] cout<<endl;return 0; 2017年4月26日12时17分 HOM正 第5章数组 11 BACK NEXT
HOME2017年4月26日12时17分 第5章 数组 11 #include #include using namespace std; int main( ) { int i,f[20]={1,1}; for(i=2;i<20;i++) f[i]=f[i-2]+f[i-1]; for(i=0;i<20;i++) { if(i%5==0) cout<<endl; cout<<setw(8)<<f[i]; }cout<<endl; return 0; }
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 川北医学院:《C++程序设计》课程教学资源(课件讲稿)第4章 函数与预处理.pdf
- 川北医学院:《C++程序设计》课程教学资源(课件讲稿)第3章 程序设计初步.pdf
- 川北医学院:《C++程序设计》课程教学资源(课件讲稿)第2章 数据类型与表达式 Data Types & Expression.pdf
- 川北医学院:《C++程序设计》课程教学资源(课件讲稿)第1章 C++的初步知识(主讲:祝元仲)C++ Programming.pdf
- 同济大学:《Visual Basic程序设计简明教程》配套PPT课件讲稿(第三版)第10章 数据库应用基础.ppt
- 同济大学:《Visual Basic程序设计简明教程》配套PPT课件讲稿(第三版)第7章 用户界面设计、第8章 数据文件、第9章 图形操作.ppt
- 同济大学:《Visual Basic程序设计简明教程》配套PPT课件讲稿(第三版)第4章 VB控制结构、第5章 数组和自定义类型、第6章 过程.ppt
- 同济大学:《Visual Basic程序设计简明教程》配套PPT课件讲稿(第三版)第1章 Visual Basic程序设计概述、第2章 VB可视化编程基础、第3章 VB语言基础.ppt
- 甘肃农业大学:《VB程序设计基础》课程教学资源(PPT讲稿)C语言概述.ppt
- 甘肃农业大学:《VB程序设计基础》课程教学资源(作业习题)VB习题1.pdf
- 甘肃农业大学:《VB程序设计基础》课程教学资源(授课教案)第一章 VB概述.doc
- 甘肃农业大学:《VB程序设计基础》课程教学资源(教学大纲)Programming of Visual Basic.pdf
- Connectivity Analysis in Wireless Networks with Correlated Mobility and Cluster Scalability.pdf
- Asymptotic Analysis on Content Placement and Retrieval in MANETs.pdf
- Are we connected? Optimal Determination of Source-destination Connectivity in Random Networks.pdf
- Mobility Weakens the Distinction between Multicast and Unicast.pptx
- Mobility Weakens the Distinction between Multicast and Unicast.pdf
- Impact of Social Relation and Group Size in Multicast Ad Hoc Networks.pptx
- Impact of Social Relation and Group Size in Multicast Ad Hoc Networks.pdf
- Optimal Secrecy Capacity-Delay Tradeoff in Large-Scale Mobile Ad Hoc Networks.pdf
- 川北医学院:《C++程序设计》课程教学资源(课件讲稿)第6章 指针.pdf
- 川北医学院:《C++程序设计》课程教学资源(课件讲稿)第8章 类和对象.pdf
- 川北医学院:《C++程序设计》课程教学资源(课件讲稿)第10章 运算符重载.pdf
- 川北医学院:《C++程序设计》课程教学资源(课件讲稿)第11章 继承与派生.pdf
- 川北医学院:《C++程序设计》课程教学资源(课件讲稿)第12章 多态性与虚函数 Polymorphism & Virtual Functions.pdf
- 川北医学院:《C++程序设计》课程教学资源(课件讲稿)第9章 关于类和对象的进一步讨论.pdf
- 川北医学院:《单片机原理》课程教学资源(教学大纲)单片机原理与应用技术 Monolithic principle and application technology.pdf
- 川北医学院:《单片机原理》课程教学资源(考试大纲).pdf
- 川北医学院:《单片机原理》课程教学资源(教案)生物医学工程专业.pdf
- 川北医学院:《单片机原理》课程教学资源(讲稿,共八章)生物医学工程专业.pdf
- 川北医学院:《单片机原理》课程教学资源(讲义)第1章 基础知识.pdf
- 川北医学院:《单片机原理》课程教学资源(讲义)第2章 单片机的结构原理与简单应用.pdf
- 川北医学院:《单片机原理》课程教学资源(讲义)第3章 8051指令系统.pdf
- 川北医学院:《单片机原理》课程教学资源(讲义)第4章 汇编语言程序设计.pdf
- 川北医学院:《单片机原理》课程教学资源(讲义)第5章 中断系统.pdf
- 川北医学院:《单片机原理》课程教学资源(讲义)第6章 定时器/计数器.pdf
- 川北医学院:《单片机原理》课程教学资源(讲义)第7章 并行扩展技术.pdf
- 川北医学院:《单片机原理》课程教学资源(讲义)第8章 串行通信.pdf
- 川北医学院:《单片机原理》课程教学资源(讲义)第9章 串行扩展技术.pdf
- 烟台理工学院:《Python程序设计》课程教学资源(教学大纲)理论课教学大纲(自动化和机器人工程专业大一本科、人工智能专业大二本科).docx