0% found this document useful (0 votes)
43 views15 pages

10.2 - Arrays (1D and 2D)

A 2D array is declared to store the temperature data for 3 cities over 7 days. The pseudo code initializes all elements of the 2D array to -5. A nested for loop is used to iterate through each row and column to assign the initial value.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views15 pages

10.2 - Arrays (1D and 2D)

A 2D array is declared to store the temperature data for 3 cities over 7 days. The pseudo code initializes all elements of the 2D array to -5. A nested for loop is used to iterate through each row and column to assign the initial value.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

ARRAYS

AS level Computer Science 9618


Session 2020-21
GUESS THE OUTPUT
INPUT

 Mark=0
2
 FOR count = 1 to 5
3
 INPUT Mark
5
 OUTPUT( Mark )
9
4
ARRAY DECLARATION
LOWER AND UPPER
BOUNDARY

STUDENT_ID : ARRAY[1:100] OF INTEGER


STUDENT_NAME : ARRAY[1:100] OF STRING

1 101 Absar
2 102 Zawad
3 103 Maher
Student_Name[3]=Maher
-- --
-- --

100 200 walid


LINEAR SEARCH IN AN ARRAY

Arif Mahdi Roshan Dilip Kareen Linda Massa Erik

INPUT NAME
Found=False
FOR count = 1 to 8
IF Student_Name[count]=NAME
Found=True
position=count
IF Found=True
OUTPUT “ Found in position”, position
ELSE
OUTPUT “ Not Found”
SWAP VALUES NUMBER

50 30 60 65

[1]. [2]. [3]. [4]


Milk Water

TEMP=NUMBER[3]
Temp NUMBER[3]=NUMBER[4]
NUMBER[4]=TEMP
BUBBLE SORT ID[5]

3 5 2 4 1
[1] [2] [3] [4] [5]

FOR outer = 1 TO 4
FOR count=1 TO 4
IF ID[count]>ID[count+1]
temp=ID[count]
ID[count]=ID[count+1]
ID[count+1]=temp
END FOR
END FOR
3 5 2 4 1

INNER LOOP Highest value got his own


position

AFTAR FIRST LOOP

3 2 4 1 5
2nd Highest value got his
own position
AFTAR 2nd LOOP

2 3 1 4 5

AFTAR 3rd LOOP


2 1 3 4 5
2D ARRAY
 It is an array of arrays.
 position of an data element is referred by two indices instead of one(Linear).

[2,3] position
DECLARATION AND
INITIALIZATION
FOR i =1 to 3
DECLARE Mark : ARRAY[3][4] of INT FOR j= 1 to 4
Mark[ i ] [ j ]=0
or

Mark=[3][4] 0000
0000
0000
ACCESSING ARRAY ELEMENT
FOR i =1 to 3
FOR j= 1 to 4
Mark[ i ] [ j ]=0 Mark [2][3]= 1

0000
0000 0010
0000 0000
0000
DISPLAY 2D ARRAY
FOR i =1 to 3
FOR j= 1 to 4
OUTPUT Mark[ i ] [ j ]
ACTIVITY
 Write a pseudo code to take a name from user and find his number from already stored arrays (
NAME[] and MARKS[ ])

 Consider there is 2D array to hold NAMES of students along with ENGLISH and BANGALI
marks. Write a pseudo code to take a name from user to return his BANGALI MARKS from
Array.
ACTIVITY
Write a pseudo code to create a table like below to have students marks and their names . Headings and Names Can be ignored.
NAME. PHY CHEM. BIO
ABSAR. 0 0 0
KAFIL. 0 0 0
MASRUR. 0 0 0

After creating the array insert “A” to all student for PHYSICS as shown below.

NAME. PHY CHEM. BIO


ABSAR. A 70 75
KAFIL. A 55 95
MASRUR. A 66 80
ACTIVITY
An array to be created to store temperature of week for three different cities in Bangladesh.
Write pseudo code to declare the array with initial value to -5, each day for all each cities.

-5 -5 -5

-5 -5 -5

-5 -5 -5

-5 -5 -5

-5 -5 -5

-5 -5 -5

-5 -5 -5
FLIP IMAGE

1 B 0 0 B 1
1 B 0 0 B 1
1 B 0 0 B 1
1 B 0 0 B 1

Data=[4][3]

You might also like