1 / 11

数组定义回顾

数组类型. 数组定义回顾. type data = array[1..50] of integer; var x : data ;. 方式一,先构造,再定义. x 为数组变量. 方式二,构造与定义同时. var x : array [1..50] of integer;. 编程实现:输入 n 个 100 以内的整数,如何要求在输出平均值. 同时还要输出高于平均值的数。( n 在 20 以内). var p:real; n,i,s:integer; x:array[1..20] of integer; begin readln(n);

ross-osborn
Download Presentation

数组定义回顾

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 数组类型 数组定义回顾 type data=array[1..50] of integer; var x:data; 方式一,先构造,再定义 x为数组变量 方式二,构造与定义同时 varx:array[1..50] of integer;

  2. 编程实现:输入n个100以内的整数,如何要求在输出平均值编程实现:输入n个100以内的整数,如何要求在输出平均值 同时还要输出高于平均值的数。(n在20以内) var p:real; n,i,s:integer; x:array[1..20] of integer; begin readln(n); s:=0; for i:= 1 to n do begin read(x[i]); s:=s+x[i]; end; p:=s/n; writeln(p:0:2); for i:=1 to n do if x[i]>p then write(x[i],’ ‘) end. var p:real; n,i,x,s:integer; begin readln(n); s:=0; for i:= 1 to n do begin read(x); s:=s+x; end; p:=s/n; writeln(p:0:2); end. 样例: 输入: 3 50 60 55 输出: 55.00 60

  3. 数组的基本操作 • 数组的输入、输出 • 数组元素的查找 • 数组元素的移动 • 数组元素的插入 • 数组元素的删除 • 排序 题目:1117-1123

  4. A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[9] A[10] 数组元素的输入、输出 例:按照顺序读入十个数,然后以逆序方式输出。 for i:=1 to 10 do read(a[i]); {输入} for i:=10 downto 1 do write(a[i]); {输出}

  5. 题1117:【入门】数组逆序 Description 给你m个整数,将其逆序输出 Input 第一行一个整数m(3 <= m <= 100 ):数的个数 第二行m个整数(空格隔开)(这些数在0-9999999之间) Output m个整数(空格隔开) Hint 最后一个数后面没有空格 Sample Input 3 1 7 5 Sample Output 5 7 1

  6. 题1118:【入门】数组元素的查找 给你m个整数,查找其中有无值为n的数,有则输出该数第一次出现的位置,没有则输出-1。 Input 第一行一个整数m:数的个数 ( 0 <= m <= 100 ) 第二行m个整数(空格隔开)( 这些数在 0-999999范围内 ) 第三行为要查找的数n Output n的位置或-1 Sample Input 4 1 2 3 3 3 Sample Output 3

  7. A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[9] A[10] 9 12 64 77 23 29 17 81 13 1 数组元素的查找 顺序查找法 从头开始,根据给定的值,依次与数组中元素进行比较,相同即为找到,若查遍整个数组仍然没有,则表示该元素不存在。 i X

  8. 1120: 【入门】数组元素的移动 题目描述 数组元素的移动,把数组的第x个位置的元素先保存起来,然后把x+1到n的元素,依次往前移一位,最后原来的第x个位置的元素放在最后 输入 有3行 第一行有一个整数n 第二行有n个整数 第三行有一个整数x 输出 移动后的数组 样例输入 8 1 2 3 4 5 6 7 8 1 样例输出 2 3 4 5 6 7 8 1

  9. 数组元素的移动 A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[9] A[10] 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 2 3 4 5 6 7 8 9 10 10 1 2 3 4 5 6 7 8 9 10 第一步: 取出A[1]中的数放t中 1 第二步: 后面所有元素向前移动 第三步: 将t中的值放到A[10]处 1

  10. 题1122:数组元素的删除 把一个数组的第x个位置的元素删除掉 Input 有三行 第一行有一个整数n 第二行有n个整数 第三行有一个整数x,为要删除的位置 Output输出更新后的数组 Sample Input 5 1 2 3 4 5 3 Sample Output 1 2 4 5

  11. A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[9] A[10] 9 12 64 77 23 29 17 81 13 1 数组元素的删除 删除一组数组中的第p个元素

More Related