03 C++ C 程序中的数组

上传人:油条 文档编号:30643610 上传时间:2018-01-31 格式:PPT 页数:40 大小:2.84MB
返回 下载 相关 举报
03  C++ C 程序中的数组_第1页
第1页 / 共40页
03  C++ C 程序中的数组_第2页
第2页 / 共40页
03  C++ C 程序中的数组_第3页
第3页 / 共40页
03  C++ C 程序中的数组_第4页
第4页 / 共40页
03  C++ C 程序中的数组_第5页
第5页 / 共40页
点击查看更多>>
资源描述

《03 C++ C 程序中的数组》由会员分享,可在线阅读,更多相关《03 C++ C 程序中的数组(40页珍藏版)》请在金锄头文库上搜索。

1、03 C+ 程序中的数组,数组的定义,数组的定义类型 数组名 常量表达式 float sheep10;int a20011000;强调:数组下标从0开始int a10= 1,2,3,4,5,6,7,8,9,10;,关于数组的定义 (1/3),#includeusing namespace std;int main()int n = 10;int an = 0 ;for (int i = 0; i n; i+)cout ai;return 0;,此处应为常量表达式,关于数组的定义 (2/3),#include using namespace std;int main()const int i =

2、 4;int ai = 1, 2, 3, 4 ;cout a0= a0 endl a1= a1 endl a2= a2 endl a3= a3 endl;return 0;,关于数组的定义 (3/3),#include using namespace std;#define N 4int main()int aN = 1, 2, 3, 4 ;cout a0= a0 endl a1= a1 endl a2= a2 endl a3= a3 endl;return 0;,数组的初始化,int a10 = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ;,数组的初始化 (1/5),#in

3、clude using namespace std;int main()int a4;cout a0 a1 a2 a3 endl;return 0;,数组的初始化 (2/5),#include using namespace std;int main()int a= 1, 2, 3, 4 ;cout a0 a1 a2 a3 endl;return 0;,数组的初始化 (3/5),#include using namespace std;int main()int a4= 1, 2;cout a0 a1 a2 a3 endl;return 0;,数组的初始化 (4/5),#include usi

4、ng namespace std;int main()int a4= 0;cout a0 a1 a2 a3 endl;return 0;,数组的初始化 (5/5),#include using namespace std;int main()int a= 1, 2, 3, 4, 5, 6;cout a0 a1 a2 a3 endl;return 0;,从 一维数组 到 二维数组,int a12 = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ;,二维数组,int a34;,二维数组的初始化 (1/6),#include #include using namesp

5、ace std;int main()int a34 = 1, 2, 3, 4 , 5, 6, 7, 8 , 9, 10, 11, 12 ;for (int i = 0; i 3; i+)for (int j = 0; j 4; j+)cout setw(3) aij;cout endl;return 0;,二维数组的初始化 (2/6),#include #include using namespace std;int main()int a34 = 1, 2, 3, 4 , 5, 6, 7, 8 , 9, 10, 11, 12 ;for (int i = 0; i 3; i+)for (int

6、 j = 0; j 4; j+)cout setw(3) aij;cout endl;return 0;,二维数组的初始化 (2/6),#include #include using namespace std;int main()int a 4 = 1, 2, 3, 4 , 5, 6, 7, 8 , 9, 10, 11, 12 ;for (int i = 0; i 3; i+)for (int j = 0; j 4; j+)cout setw(3) aij;cout endl;return 0;,二维数组的初始化 (4/6),#include #include using namespace

7、 std;int main()int a 4 = 1, 0, 6, 0, 0, 11;for (int i = 0; i 3; i+)for (int j = 0; j 4; j+)cout setw(3) aij;cout endl;return 0;,二维数组的初始化 (5/6),#include #include using namespace std;int main()int a34 = 0;for (int i = 0; i 3; i+)for (int j = 0; j 4; j+)cout setw(3) aij;cout endl;return 0;,二维数组的初始化 (6/

8、6),int main()int a34 = 0 ;for (int i = 0; i 3; i+)for (int j = 0; j 4; j+)aij = 4 * i + j + 1;for (int i = 0; i 3; i+)for (int j = 0; j 4; j+)cout setw(3) aij;cout endl;return 0;,二维数组,int a34;,a34; a434; a34; a334; a34; a234; a34; a134; a34; a034;,三维数组,三维数组,int a534;,三维数组,int a534;,int a34;,int main

9、()int a534 = 0 ;for (int i = 0; i 5; i+)for (int j = 0; j 3; j+)for (int k = 0; k 4; k+)aijk = 12 * i + 4 * j + k + 1;for (int i = 0; i 5; i+)for (int j = 0; j 3; j+)for (int k = 0; k 4; k+)cout setw(3) aijk;cout endl;cout num;for (j = 0; j num;for (int j = 0; j 10; j+)if (num = j) countj+;for (int

10、i = 0; i 10; i+)if (counti != 0) cout i 输入了 counti 次 num;switch(num) case 0 : count0+;break; case 1 : count1+;break;case 2 : count2+;break;- ,#include using namespace std;int main()int num, count10 = 0;for (int i = 1; i num;switch (num)case 0: count0+; break;case 1: count1+; break;case 2: count2+; b

11、reak;case 3: count3+; break;case 4: count4+; break;case 5: count5+; break;case 6: count6+; break;case 7: count7+; break;case 8: count8+; break;case 9: count9+; break;for (int i = 0; i 10; i+)if (counti != 0)cout i 输入了 counti 次 num;countnum+;,#include using namespace std;int main()int num, count10 = 0;for (int i = 0; i num;countnum+;for (int i = 0; i 10; i+) if (counti != 0) cout i 输入了counti 次endl;return 0;,例2 数字统计,问题某学校有1000位老师,分布在20个不同的学院中,每个学院最多有12个系,请你编写一个程序,输入每位老师的所在院、系的编号(院编号1-20,系编号1-12),打印出各个系老师的数量。分析你的解决方案?,

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号