This material aims to enable students to:
1. Know and understand how to use array and record
2. Know and could implement how to declare data type of array and record in C
3. Make a simple program that involves one-dimensional array and two-dimensional array in C
4. Make a simple program using record in C
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Algorithm and Data Structure - Array and Struct
1. Algorithm and
Data Structure
Andi Nurkholis, S.Kom, M.Kom
Study Program of Informatics
Faculty of Engineering and Computer Science
SY. 2020-2021
February 22, 2021
3. 3
What is Array?
Array also known as “larik”. Array is data collections
with each data element using same name and type
Each component/element of array can be accessed
and distinguished through index
4. 4
Type of Array 1) One-Dimensional Array
2) Multi-Dimensional Array
5. 5
One-Dimensional Array
A collection of identical elements arranged in a row. These
elements have the same data type, but content of those elements
may be different
10. 10
Record / Struct
Record is data collections that is not similar or
varied. In C, record also known as struct
The difference between record and array is that
record can be filled with data that have different data
type
12. 12
Example (Cont.)
struct mahasiswa { char nama[20]; char npm[10], int nilai;
} nilaiMhs;
nilaiMhs.nama;
nilaiMhs.npm;
nilaiMhs.nilai;
Declaration
Access
13. 13
Record in Array
Record in array make it possible to store record data in an array
index.
That is, using this technique can store some data that has different
data types in an array
For example, some students can have a name and value.
16. 16
Array in Record
Arrays in a record make it possible to store array data in a record.
That is, using this technique can store multiple indexes of array
data into a record that has a different data type.
For example, a student can have a name and several grades.
19. 19
Array in Array Record
Arrays in a array record make it possible to store array data in a
array record.
That is, using this technique can store multiple indexes of array
data into multiple record that has a different data type.
For example, each of student can have a name and several grades.
20. 20
Example
General form of array in record array
struct nama_type_record {tipe_data1 nm_var1[ArrayElement];
tipe_data2 nm_var2[ArrayElement];
tipe_dataN nm_varN;[ArrayElement]}
var_record[ArrayElement];
21. 21
Example (Cont.)
struct mahasiswa { char nama[20][3]; int nilai[3];
} nilaiMhs[3];
nilaiMhs[1].nama[0];
nilaiMhs[1].nilai[0];
Declaration
Access
22. Thank You, Next …
Modular Programming
February 22, 2021
Andi Nurkholis, S.Kom, M.Kom
Study Program of Informatics
Faculty of Engineering and Computer Science
SY. 2020-2021