·N-S流程图 输入n个数给[1到a[n for j=1 to n-1 for i=1 to n-J 真a[>a+1假 a[ika[i+1] 输出a[1到an
• N-S流程图 输入n个数给a[1]到a[n] 真 a[i]>a[i+1] 假 a[i] a[i+1] 输出a[1]到a[n] for j=1 to n-1 for i=1 to n-j
例:统计字符,数字0—9各多少,看不见的空 格、回车、tab及其他字符出现的次数 1.#include"stdio. h 2. main() 3. int C, i, nwh, nother, ndig[10=(] 4 nwh=nother=0 5. While((c=getchar(=EOF 6.f(c>=0&&c<=9")++ndig[c0] 7. else if(c==llc==nc==t)++nwh; 8. else ++nother 9.for(=0i<10;++) 10. printf("n%d: %d, i, ndig[] printf("white space=%d, other=%d\n", nwh, nother), y
***** • 例:统计字符,数字0-9各多少,看不见的空 格、回车、tab及其他字符出现的次数 1. #include"stdio.h" 2. main( ) 3. {int c,i,nwh,nother,ndig[10]={0}; 4. nwh=nother=0; 5. while((c=getchar( ))!=EOF) 6. if(c>='0'&&c<='9') ++ndig[c-'0']; 7. else if(c==' '||c=='\n'||c=='\t') ++nwh; 8. else ++nother; 9. for(i=0;i<10;i++) 10. printf("\n%d:%d,",i,ndig[i]); 11.printf("white space=%d,other=%d\n",nwh,nother);}
大大大大大 运行时输入:00111343456789cmz 运行结果: 0:2 1:3 2:0 3:2 4:2 5:1 6:1 7:1 8:1 9: 1 While space=3, other=0
***** • 运行时输入:00 111 3434 56789 • 运行结果: 0:2 1:3 2:0 3:2 4:2 5:1 6:1 7:1 8:1 9:1 while space=3,other=0 Ctrl z
二维数组的定义和引用 二维数组的定义 般形式: 类型说明符数组名[常量表达式[常量表达式] 例如: float a③3[4,b510] 注意:不能写成 float a34],b5,10 C语言把二维数组看作是一种特殊的一维数 组:它的元素又是一个一维数组
二维数组的定义和引用 • 二维数组的定义 • 一般形式: 类型说明符 数组名[常量表达式] [常量表达式] 例如: float a[3][4],b[5][10]; 注意:不能写成 float a[3,4],b[5,10]; • C语言把二维数组看作是一种特殊的一维数 组:它的元素又是一个一维数组
float al③I 可以看成: float al04a1[4]a2]4] alo a 00 a 01a02 a 03 个一维数组名 aa1]--a10a11a12a13 a2]-20a21a22a23 按行存储 aoo ao1 a02 a03 a10a11a12a13 a2n a21 a22 a 23
• float a[3][4] 可以看成:float a[0][4],a[1][4],a[2][4]; a[0]---------a00 a01 a02 a03 a a[1]---------a10 a11 a12 a13 a[2]---------a20 a21 a22 a23 a00 a01 a02 a03 a10 a11 a12 a13 a20 a21 a22 a23 按行存储 三 个 一 维 数 组 名