计算机C语言精讲课件双语_第1页
计算机C语言精讲课件双语_第2页
计算机C语言精讲课件双语_第3页
计算机C语言精讲课件双语_第4页
计算机C语言精讲课件双语_第5页
已阅读5页,还剩29页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、1,Chap 7 arrays 数 组,2,7.2 one-dimensional arrays,1、declaration of one-dimensional arrays type array-namesize; For example: int a10; char c200; float f5;,3,2、array item,array-namesize; arrange:0,size-1 int a10; a0、a1、 a9 array-namesubscript a10 overflow scanf(%d, ,4,initialization of one-demensional

2、array,type array-namesize=list of values; int a10 = 1,2,3,4,5,6,7,8,9,10; a0=1, a1=2,. a9=10,5,int b5 = 1, 2, 3; b0 = 1, b1 = 2, b2 = 3, b3 = ?, b4 = ? int a = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9;,6,for(i = 0; i n; i+) printf(%d , ai);,7,Input 10 numbers ,save them in arrays, then print them,8,Calculate an

3、d print the first m Fibonacci numbers 1, 1, 2, 3, 5, 8, 13, f0 = f1 = 1 fn = fn-1 + fn-2 2n19,Fibonacci numbers 1,1,2,3,5,8,13,21,34,55,#include int main(void) int i; int fib20 = 1, 1; for(i = 2; i 20; i+) fibi = fibi - 1 + fibi - 2; for(i = 0; i 20; i+) printf(%6d, fibi); if(i + 1) % 5 = 0) printf(

4、n); return 0; ,1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765,10,Input 5 integers ,save them in array ,then input one number x, to find x in array, if you can find,print its subscript, otherwise print “Not Found”。 Input :2 9 8 9 6 9 Output :1 Input :2 9 8 9 6 7 output:Not Found,E

5、xample:,#include int main(void) int i, flag, x; int a5; printf(“Enter 5 integers: ); for(i = 0; i 5; i+) scanf(%d, ,Enter 5 integers: 2 9 8 1 9 Enter x: 9 Index is 1,Enter 5 integers: 2 9 8 1 9 Enter x: 7 Not Found,12,Output minimum,Input m numbers, then print the minimum,13,#include int main(void)

6、int i, min, n; int a10; printf(“Enter n: ); scanf(%d, ,print minimum,Enter n: 6 Enter 6 integers: 2 9 -1 8 1 6 min is -1,14,Input m numbers, then print the minimum and subscript Index is subscript of minimum aindex is minimum,print minimum and subscript,15,#include int main(void) int i, index, n; in

7、t a10; printf(“Enter n: ); scanf(%d, ,program,Enter n: 6 Enter 6 integers: 2 9 -1 8 1 6 min is -1 sub is 2,16,Chang two numbers x y x=y y=x Z=x x=y y=z,17,Input n(n a0,Change minimum,selection sort,Inout n(n10), then input n numbers ,print them from small To large For example n=5 3 5 2 8 1,(1) 1 5 2

8、 8 3 (2) 2 5 8 3 (3) 3 8 5 (4) 5 8,19,5 2 8 1 (n=5) Find minimum from 5 numbers (a0a4) ,exchange it and a0 1 5 2 8 3 a4 a0 Find minimum from 4 numbers(a1a4) ,exchange it and a1 (2) 1 2 5 8 3 a2 a1 Find minimum from 3 numbers(a2a4) ,exchange it and a2 (3) 1 2 3 8 5 a4 a2 Find minimum from 3numbers(a2

9、a4) ,exchange it and a3 (4) 1 2 3 5 8 a4 a3,20,(1) Find minimum from n numbers (a0an) ,exchange it and a0 (2) Find minimum from n-1 numbers(a1an) ,exchange it and a1 (n-1) Find minimum from 2 numbers (an-2an-1) ,exchange it and an-2,21,selection sort,for(k = 0; k n-1; k+) index = k; for(i = k + 1; i

10、 n; i+) if(ai aindex) index = i; temp = aindex; aindex = ak; ak = temp; ,Enter n: 5 Enter 10 integers: 3 5 2 8 1 After sorted: 1 2 3 5 8,23,Two-dimensional arrays,24,declaration of two-dimensional arrays,1、 type array-namerow-sizecolumn-size; int a32; a00 a01 a10 a11 a20 a21 int b510;,25,initializat

11、ion of two-dimensional arrays,1、int a33 = 1,2,3,4,5,6,7,8,9; int b43 = 1,2,3, ,4,5; static int b 3=1,2,3,4,5,Array a 1 2 3 4 5 6 7 8 9,Array b 1 2 3 0 0 0 4 5 0 0 0 0,2 int a33 = 1,2,3,4,5,6,7,8,9; int b43 = 1,2,3,0,0,0,4,5;,26,When the array is completely initialized with all values,we need not spe

12、cify the size of the first dimension int a 3=1,2,3,4,5,6,7,8,9; static int b 3=1,2,3,4,5,Array a 1 2 3 4 5 6 7 8 9,Array b 1 2 3 0 0 0 4 5 0 0 0 0,27,Nesting of loop for two-dimensional arrays,Declare a array with two cows and three columns , input data then display them,28,Declare matrix a with thr

13、ee cows and two columns,the value of the element is computed as follows: aij = i + j(0i2,0j1) Display this matrix,int a32; a00 a01 a10 a11 a20 a21,0 1 1 2 2 3,29,#include int main(void) int i, j; int a32; for(i = 0; i 3; i+) for(j = 0; j 2; j+) aij = i + j; for(i = 0; i 3; i+) for(j = 0; j 2; j+) pr

14、intf(%4d, aij); printf(n); return 0; ,a00 a01 a10 a11 a20 a21,i = 0 j = 0 i = 0 j = 1 i = 1 j = 0 i = 1 j = 1 i = 2 j = 0 i = 2 j = 1,program,0 1 1 2 2 3,30,int aNN; N is integer data aij:arrange of the value of i、j :0,N-1 maindiagonal of a squarematrix upper triangular matrix low triangular matrix,31,About matrix of size n*n a00 a01 a02 主对角线 a10 a11 a12 上三角 a20 a21 a22 下三角,i=j i=j,32,Display upper triangular matrix For(i=0;i3;i+) For(j=i;j3;j+) Display low triangular matrix For(i=0;i3;i+) For(j=0;j=i;j+),33

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论