SlideShare a Scribd company logo
C ARRAYS
-a collection of same type data, 1D,
2D-
www.tenouk.com, © 1/25
Agenda
1- Warm up Listen to this video about motivating programmers 5 min
2- ppt teacher demonstrate about Arrays in C programming 25 min
3- Video about how we can use c programming in real life projects ,
automation and solving problems 3 min
4- Students play or act a game about simulating loops 10 min
5- practical work using lap tops through code blocks in implement a
small program work in pairs 10 min
6- use netacade.com to self learn C and get certificate from CISCO 5 m
7- Questions and answers 20 min
8-Refelection 5 min
9- Home work
LO CS.2.03 - Students should
know how to define / declare and
initialize arrays and
multidimensional arrays types . so
they can apply this knowledge
during implementation of software
application .
Lesson plan
Warm Up
Listen to this video offline
Listen to this video on line
Essential Question
1- How can you use array
in programming?
Warm Up
Listen to this video offline
Listen to this video on line
Warm Up
Listen to this video offline
Listen to this video on line
ARRAYS
 An array is a collection of elements of the same type that
are referenced by a common name.
 Compared to the basic data type (int, float & char) it is
an aggregate or derived data type.
 All the elements of an array occupy a set of contiguous
memory locations.
 Why need to use array type?
 Consider the following issue:
"We have a list of 1000 students' marks of an
integer type. If using the basic data type (int),
we will declare something like the following…"
int studMark0, studMark1, studMark2, ..., studMark999;
www.tenouk.com, © 2/25
ARRAYS
 Can you imagine how long we have to write
the declaration part by using normal variable
declaration?
int main(void)
{
int studMark1, studMark2, studMark3,
studMark4, …, …, studMark998, stuMark999,
studMark1000;
…
…
return 0;
}
www.tenouk.com, © 3/25
ARRAYS
 By using an array, we just declare like this,
int studMark[1000];
 This will reserve 1000 contiguous memory locations for storing the
students’ marks.
 Graphically, this can be depicted as in the following figure.
www.tenouk.com, © 4/25
ARRAYS
 This absolutely has simplified our declaration of the
variables.
 We can use index or subscript to identify each
element or location in the memory.
 Hence, if we have an index of jIndex,
studMark[jIndex] would refer to the jIndexth
element in the array of studMark.
 For example, studMark[0] will refer to the first
element of the array.
 Thus by changing the value of jIndex, we could refer
to any element in the array.
 So, array has simplified our declaration and of course,
manipulation of the data.
www.tenouk.com, © 5/25
ARRAYS
One Dimensional Array: Declaration
 Dimension refers to the array's size, which is how big the
array is.
 A single or one dimensional array declaration has the
following form,
array_element_data_type array_name[array_size];
 Here, array_element_data_type define the base type of the
array, which is the type of each element in the array.
 array_name is any valid C / C++ identifier name that obeys
the same rule for the identifier naming.
 array_size defines how many elements the array will hold.
www.tenouk.com, © 6/25
ARRAYS
 For example, to declare an array of 30 characters, that
construct a people name, we could declare,
char cName[30];
 Which can be depicted as follows,
 In this statement, the array character can store
up to 30 characters with the first character
occupying location cName[0] and the last
character occupying cName[29].
 Note that the index runs from 0 to 29. In C, an
index always starts from 0 and ends with array's
(size-1).
 So, take note the difference between the array
size and subscript/index terms.
www.tenouk.com, © 7/25
ARRAYS
 Examples of the one-dimensional array declarations,
int xNum[20], yNum[50];
float fPrice[10], fYield;
char chLetter[70];
 The first example declares two arrays named xNum and yNum of type
int. Array xNum can store up to 20 integer numbers while yNum can
store up to 50 numbers.
 The second line declares the array fPrice of type float. It can
store up to 10 floating-point values.
 fYield is basic variable which shows array type can be declared
together with basic type provided the type is similar.
 The third line declares the array chLetter of type char. It can store a
string up to 69 characters.
 Why 69 instead of 70? Remember, a string has a null terminating
character (0) at the end, so we must reserve for it.
www.tenouk.com, © 8/25
ARRAYS
Array Initialization
 An array may be initialized at the time of declaration.
 Giving initial values to an array.
 Initialization of an array may take the following form,
type array_name[size] = {a_list_of_value};
 For example:
int idNum[7] = {1, 2, 3, 4, 5, 6, 7};
float fFloatNum[5] = {5.6, 5.7, 5.8, 5.9, 6.1};
char chVowel[6] = {'a', 'e', 'i', 'o', 'u', '0'};
 The first line declares an integer array idNum and it immediately
assigns the values 1, 2, 3, ..., 7 to idNum[0], idNum[1],
idNum[2],..., idNum[6] respectively.
 The second line assigns the values 5.6 to
fFloatNum[0], 5.7 to fFloatNum[1], and so on.
 Similarly the third line assigns the characters 'a' to chVowel[0], 'e' to
chVowel[1], and so on. Note again, for characters we must use the
single apostrophe/quote (') to enclose them.
 Also, the last character in chVowel is NULL character ('0').
www.tenouk.com, © 9/25
ARRAYS
 Initialization of an array of type char for holding strings may take the following
form,
char array_name[size] = "string_lateral_constant";
 For example, the array chVowel in the previous example could have been
written more compactly as follows,
char chVowel[6] = "aeiou";
 When the value assigned to a character array is a string (which must be
enclosed in double quotes), the compiler automatically supplies the NULL
character but we still have to reserve one extra place for the NULL.
 For unsized array (variable sized), we can declare as follow,
char chName[ ] = "Mr. Dracula";
 C compiler automatically creates an array which is big enough to hold all the
initializer.
www.tenouk.com, © 16/25
ARRAYS
 Arrays allow programmers to group related items of the same
data type in one variable.
 However, when referring to an array, one has to specify not only
the array or variable name but also the index number of interest.
 Program example 1: Sum of array’s element.
 Notice the array's element which is not initialized is set to 0
automatically.
www.tenouk.com, © 17/25
ARRAYS
 Program example 2: Searching the smallest value.
 Finding the smallest element in the array named fSmallest.
 First, it assumes that the smallest value is in fSmallest[0] and
assigns it to the variable nSmall.
 Then it compares nSmall with the rest of the values in fSmallest,
one at a time.
 When an element is smaller than the current value contained in
nSmall, it is assigned to nSmall. The process finally places the
smallest array element in nSmall.
www.tenouk.com, © 18/25
ARRAYS
 Program example 3: Searching the biggest
value. By modifying the previous example we
can search the biggest value.
www.tenouk.com, © 19/25
ARRAYS
 Program example 5: Storing and reading
a string
www.tenouk.com, © 20/25
ARRAYS
 Program example 6: Storing and reading array
content and its index
www.tenouk.com, © 21/25
ARRAYS
Two Dimensional/2D Arrays
 A two dimensional array has two subscripts/indexes.
 The first subscript refers to the row, and the second, to the column.
 Its declaration has the following form,
data_type array_name[1st dimension size][2nd dimension size];
 For examples,
int xInteger[3][4];
float matrixNum[20][25];
 The first line declares xInteger as an integer array with 3 rows and
4 columns.
 Second line declares a matrixNum as a floating-point array with 20
rows and 25 columns.
www.tenouk.com, © 22/25
ARRAYS
 If we assign initial string values for the 2D array it will look
something like the following,
char Name[6][10] = {"Mr. Bean", "Mr. Bush", "Nicole",
"Kidman", "Arnold", "Jodie"};
 Here, we can initialize the array with 6 strings, each with
maximum 9 characters long.
 If depicted in rows and columns it will look something like the
following and can be considered as contiguous arrangement in
the memory.
www.tenouk.com, © 23/25
ARRAYS
 Take note that for strings the null character (0) still needed.
 From the shaded square area of the figure we can determine the size of the
array.
 For an array Name[6][10], the array size is 6 x 10 = 60 and equal to the
number of the colored square. In general, for
array_name[x][y];
 The array size is = First index x second index = xy.
 This also true for other array dimension, for example three dimensional
array,
array_name[x][y][z]; => First index x second index x third index = xyz
 For example,
ThreeDimArray[2][4][7] = 2 x 4 x 7 = 56.
 And if you want to illustrate the 3D array, it could be a cube with wide, long
and height dimensions.
www.tenouk.com, © 24/25
ARRAYS
 Program example 7: Storing and reading
array content and its index
www.tenouk.com, © 20/25
ARRAYS
 Program example 8: Swapping iIndex
(iRow) with jIndex (iColumn) in the
previous program example
www.tenouk.com, © 26/25
ARRAYS
1. Program example 9: Strings are read in by the rows.
2. Each row will have one string. Enter the following data:
“you”, “are”, “cat” for the following example.
3. Remember that after each string, a null character is
added.
4. We are reading in strings but printing out only characters.
www.tenouk.com, © 22/25
ARRAYS
 The contents of the array in memory after the three
strings are read in the array.
 Re-run the program, enter the following data:
“you”, “my”. Illustrates the content as done
previously.
www.tenouk.com, © 23/25
ARRAYS
1. Does your output agree?
2. How is the null character, '0' printed?
3. Is there a garbage character in a[1][3]? If so,
why?
a) The output matched, except the garbage.
b) Just an empty space.
c) Yes. This slot has been reserved but not
filled so whatever the previous data that
has been stored here would be displayed
(if possible).
www.tenouk.com, © 24/25
End-of-C-arrays
www.tenouk.com, © 25/25
practical work using lap
tops through code blocks
in implement a C small
program work in pairs
210 min
Use netacade.com to self learn
C and get certificate from
CISCO 7 7 min
Online auto answered
quiz 15 min
Reflection 5 min
• What is your goal to accomplish in
next week End Using C programming
Language ?
students create in small
groups a c program related
to their capstone project .
Home work
+ =
C program
Arduino
Arduino hardware
controller
components of irradiation
system
Home work
Discuss how to use
Arrays in coding
different programs in
a video by using office
mix.
37
Resources
watch a video that explain
different ways for Arrays and read
in the following links :
https://www.youtube.com/watch?v
=Rtww83GH0BU
38
Thank you
Collected by Eng.Osama
Grace

More Related Content

What's hot

C++ lecture 04
C++ lecture 04C++ lecture 04
C++ lecture 04
HNDE Labuduwa Galle
 
C arrays
C arraysC arrays
Arrays in c
Arrays in cArrays in c
Arrays in c
Jeeva Nanthini
 
Arrays In C
Arrays In CArrays In C
Arrays In C
yndaravind
 
Arrays
ArraysArrays
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to Arrays
Tareq Hasan
 
Arrays basics
Arrays basicsArrays basics
Arrays basics
sudhirvegad
 
C++ programming (Array)
C++ programming (Array)C++ programming (Array)
C++ programming (Array)
طارق بالحارث
 
Array in c language
Array in c languageArray in c language
Array in c languagehome
 
Array
ArrayArray
Arrays
ArraysArrays
One dimensional 2
One dimensional 2One dimensional 2
One dimensional 2
Rajendran
 
Arrays in c language
Arrays in c languageArrays in c language
Arrays in c language
tanmaymodi4
 
Array in c++
Array in c++Array in c++
Array in c++
Mahesha Mano
 
Arrays in C
Arrays in CArrays in C
Arrays in C
Kamruddin Nur
 
2- Dimensional Arrays
2- Dimensional Arrays2- Dimensional Arrays
2- Dimensional Arrays
Education Front
 
Array C programming
Array C programmingArray C programming
Array C programming
Prionto Abdullah
 

What's hot (20)

C++ lecture 04
C++ lecture 04C++ lecture 04
C++ lecture 04
 
C arrays
C arraysC arrays
C arrays
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Arrays In C
Arrays In CArrays In C
Arrays In C
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Arrays
ArraysArrays
Arrays
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to Arrays
 
Arrays basics
Arrays basicsArrays basics
Arrays basics
 
Array
ArrayArray
Array
 
C++ programming (Array)
C++ programming (Array)C++ programming (Array)
C++ programming (Array)
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Arrays
ArraysArrays
Arrays
 
Array
ArrayArray
Array
 
Arrays
ArraysArrays
Arrays
 
One dimensional 2
One dimensional 2One dimensional 2
One dimensional 2
 
Arrays in c language
Arrays in c languageArrays in c language
Arrays in c language
 
Array in c++
Array in c++Array in c++
Array in c++
 
Arrays in C
Arrays in CArrays in C
Arrays in C
 
2- Dimensional Arrays
2- Dimensional Arrays2- Dimensional Arrays
2- Dimensional Arrays
 
Array C programming
Array C programmingArray C programming
Array C programming
 

Similar to C programming , array 2020

cprogrammingarrayaggregatetype.ppt
cprogrammingarrayaggregatetype.pptcprogrammingarrayaggregatetype.ppt
cprogrammingarrayaggregatetype.ppt
georgejustymirobi1
 
cprogrammingarrayaggregatetype (1).ppt
cprogrammingarrayaggregatetype (1).pptcprogrammingarrayaggregatetype (1).ppt
cprogrammingarrayaggregatetype (1).ppt
karunapatel13
 
cprogrammingarrayaggregatetype.ppt
cprogrammingarrayaggregatetype.pptcprogrammingarrayaggregatetype.ppt
cprogrammingarrayaggregatetype.ppt
Prasanna657934
 
cprogrammingarrayaggregatetype.ppt
cprogrammingarrayaggregatetype.pptcprogrammingarrayaggregatetype.ppt
cprogrammingarrayaggregatetype.ppt
Samitbiswas10
 
Array concept
Array conceptArray concept
Array concept
Veiluvanthal1981
 
3.ArraysandPointers.pptx
3.ArraysandPointers.pptx3.ArraysandPointers.pptx
3.ArraysandPointers.pptx
FolkAdonis
 
Array.pptx
Array.pptxArray.pptx
Array in C.pdf
Array in C.pdfArray in C.pdf
Array in C.pdf
georgejustymirobi1
 
Array.pdf
Array.pdfArray.pdf
Array.pdf
mounikanarra3
 
Arrays cpu2
Arrays cpu2Arrays cpu2
Arrays cpu2
Krunal Koladiya
 
Unit 2
Unit 2Unit 2
Unit 2
TPLatchoumi
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfHomework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdf
aroraopticals15
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functionsSwarup Kumar Boro
 
C programming session 04
C programming session 04C programming session 04
C programming session 04Dushmanta Nath
 
Arrays
ArraysArrays
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
Swarup Boro
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
Thesis Scientist Private Limited
 

Similar to C programming , array 2020 (20)

cprogrammingarrayaggregatetype.ppt
cprogrammingarrayaggregatetype.pptcprogrammingarrayaggregatetype.ppt
cprogrammingarrayaggregatetype.ppt
 
cprogrammingarrayaggregatetype (1).ppt
cprogrammingarrayaggregatetype (1).pptcprogrammingarrayaggregatetype (1).ppt
cprogrammingarrayaggregatetype (1).ppt
 
cprogrammingarrayaggregatetype.ppt
cprogrammingarrayaggregatetype.pptcprogrammingarrayaggregatetype.ppt
cprogrammingarrayaggregatetype.ppt
 
cprogrammingarrayaggregatetype.ppt
cprogrammingarrayaggregatetype.pptcprogrammingarrayaggregatetype.ppt
cprogrammingarrayaggregatetype.ppt
 
Array concept
Array conceptArray concept
Array concept
 
3.ArraysandPointers.pptx
3.ArraysandPointers.pptx3.ArraysandPointers.pptx
3.ArraysandPointers.pptx
 
C%20ARRAYS.pdf.pdf
C%20ARRAYS.pdf.pdfC%20ARRAYS.pdf.pdf
C%20ARRAYS.pdf.pdf
 
Array.pptx
Array.pptxArray.pptx
Array.pptx
 
Array in C.pdf
Array in C.pdfArray in C.pdf
Array in C.pdf
 
Array.pdf
Array.pdfArray.pdf
Array.pdf
 
Module7
Module7Module7
Module7
 
Arrays cpu2
Arrays cpu2Arrays cpu2
Arrays cpu2
 
Arrays
ArraysArrays
Arrays
 
Unit 2
Unit 2Unit 2
Unit 2
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfHomework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdf
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
 
C programming session 04
C programming session 04C programming session 04
C programming session 04
 
Arrays
ArraysArrays
Arrays
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
 

More from Osama Ghandour Geris

functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...
functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...
functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...
Osama Ghandour Geris
 
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.ppt
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.pptPython week 5 2019-2020 for G10 by Eng.Osama Ghandour.ppt
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.ppt
Osama Ghandour Geris
 
Python cs.1.12 week 10 2020 2021 covid 19 for g10 by eng.osama mansour
Python cs.1.12 week 10  2020 2021 covid 19 for g10 by eng.osama mansourPython cs.1.12 week 10  2020 2021 covid 19 for g10 by eng.osama mansour
Python cs.1.12 week 10 2020 2021 covid 19 for g10 by eng.osama mansour
Osama Ghandour Geris
 
Python cs.1.12 week 9 10 2020-2021 covid 19 for g10 by eng.osama ghandour
Python cs.1.12 week 9 10  2020-2021 covid 19 for g10 by eng.osama ghandourPython cs.1.12 week 9 10  2020-2021 covid 19 for g10 by eng.osama ghandour
Python cs.1.12 week 9 10 2020-2021 covid 19 for g10 by eng.osama ghandour
Osama Ghandour Geris
 
Python week 7 8 2019-2020 for grade 10
Python week 7 8 2019-2020 for grade 10Python week 7 8 2019-2020 for grade 10
Python week 7 8 2019-2020 for grade 10
Osama Ghandour Geris
 
Python week 6 2019 2020 for grade 10
Python week 6 2019 2020 for grade 10 Python week 6 2019 2020 for grade 10
Python week 6 2019 2020 for grade 10
Osama Ghandour Geris
 
Python week 5 2019 2020 for g10 by eng.osama ghandour
Python week 5 2019 2020 for g10 by eng.osama ghandourPython week 5 2019 2020 for g10 by eng.osama ghandour
Python week 5 2019 2020 for g10 by eng.osama ghandour
Osama Ghandour Geris
 
Python week 4 2019 2020 for g10 by eng.osama ghandour
Python week 4 2019 2020 for g10 by eng.osama ghandourPython week 4 2019 2020 for g10 by eng.osama ghandour
Python week 4 2019 2020 for g10 by eng.osama ghandour
Osama Ghandour Geris
 
Programming intro variables constants - arithmetic and assignment operators
Programming intro variables   constants - arithmetic and assignment operatorsProgramming intro variables   constants - arithmetic and assignment operators
Programming intro variables constants - arithmetic and assignment operators
Osama Ghandour Geris
 
Mobile appliaction w android week 1 by osama
Mobile appliaction w android week 1 by osamaMobile appliaction w android week 1 by osama
Mobile appliaction w android week 1 by osama
Osama Ghandour Geris
 
Python week 1 2020-2021
Python week 1 2020-2021Python week 1 2020-2021
Python week 1 2020-2021
Osama Ghandour Geris
 
6 css week12 2020 2021 for g10
6 css week12 2020 2021 for g106 css week12 2020 2021 for g10
6 css week12 2020 2021 for g10
Osama Ghandour Geris
 
Css week11 2020 2021 for g10 by eng.osama ghandour
Css week11 2020 2021 for g10 by eng.osama ghandourCss week11 2020 2021 for g10 by eng.osama ghandour
Css week11 2020 2021 for g10 by eng.osama ghandour
Osama Ghandour Geris
 
Cooding history
Cooding history Cooding history
Cooding history
Osama Ghandour Geris
 
Computer networks--network
Computer networks--networkComputer networks--network
Computer networks--network
Osama Ghandour Geris
 
How to print a sketch up drawing in 3d
How to print a sketch up drawing  in 3dHow to print a sketch up drawing  in 3d
How to print a sketch up drawing in 3d
Osama Ghandour Geris
 
Google sketch up-tutorial
Google sketch up-tutorialGoogle sketch up-tutorial
Google sketch up-tutorial
Osama Ghandour Geris
 
7 types of presentation styles on line
7 types of presentation styles on line7 types of presentation styles on line
7 types of presentation styles on line
Osama Ghandour Geris
 
Design pseudo codeweek 6 2019 -2020
Design pseudo codeweek 6 2019 -2020Design pseudo codeweek 6 2019 -2020
Design pseudo codeweek 6 2019 -2020
Osama Ghandour Geris
 
Php introduction
Php introductionPhp introduction
Php introduction
Osama Ghandour Geris
 

More from Osama Ghandour Geris (20)

functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...
functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...
functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...
 
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.ppt
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.pptPython week 5 2019-2020 for G10 by Eng.Osama Ghandour.ppt
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.ppt
 
Python cs.1.12 week 10 2020 2021 covid 19 for g10 by eng.osama mansour
Python cs.1.12 week 10  2020 2021 covid 19 for g10 by eng.osama mansourPython cs.1.12 week 10  2020 2021 covid 19 for g10 by eng.osama mansour
Python cs.1.12 week 10 2020 2021 covid 19 for g10 by eng.osama mansour
 
Python cs.1.12 week 9 10 2020-2021 covid 19 for g10 by eng.osama ghandour
Python cs.1.12 week 9 10  2020-2021 covid 19 for g10 by eng.osama ghandourPython cs.1.12 week 9 10  2020-2021 covid 19 for g10 by eng.osama ghandour
Python cs.1.12 week 9 10 2020-2021 covid 19 for g10 by eng.osama ghandour
 
Python week 7 8 2019-2020 for grade 10
Python week 7 8 2019-2020 for grade 10Python week 7 8 2019-2020 for grade 10
Python week 7 8 2019-2020 for grade 10
 
Python week 6 2019 2020 for grade 10
Python week 6 2019 2020 for grade 10 Python week 6 2019 2020 for grade 10
Python week 6 2019 2020 for grade 10
 
Python week 5 2019 2020 for g10 by eng.osama ghandour
Python week 5 2019 2020 for g10 by eng.osama ghandourPython week 5 2019 2020 for g10 by eng.osama ghandour
Python week 5 2019 2020 for g10 by eng.osama ghandour
 
Python week 4 2019 2020 for g10 by eng.osama ghandour
Python week 4 2019 2020 for g10 by eng.osama ghandourPython week 4 2019 2020 for g10 by eng.osama ghandour
Python week 4 2019 2020 for g10 by eng.osama ghandour
 
Programming intro variables constants - arithmetic and assignment operators
Programming intro variables   constants - arithmetic and assignment operatorsProgramming intro variables   constants - arithmetic and assignment operators
Programming intro variables constants - arithmetic and assignment operators
 
Mobile appliaction w android week 1 by osama
Mobile appliaction w android week 1 by osamaMobile appliaction w android week 1 by osama
Mobile appliaction w android week 1 by osama
 
Python week 1 2020-2021
Python week 1 2020-2021Python week 1 2020-2021
Python week 1 2020-2021
 
6 css week12 2020 2021 for g10
6 css week12 2020 2021 for g106 css week12 2020 2021 for g10
6 css week12 2020 2021 for g10
 
Css week11 2020 2021 for g10 by eng.osama ghandour
Css week11 2020 2021 for g10 by eng.osama ghandourCss week11 2020 2021 for g10 by eng.osama ghandour
Css week11 2020 2021 for g10 by eng.osama ghandour
 
Cooding history
Cooding history Cooding history
Cooding history
 
Computer networks--network
Computer networks--networkComputer networks--network
Computer networks--network
 
How to print a sketch up drawing in 3d
How to print a sketch up drawing  in 3dHow to print a sketch up drawing  in 3d
How to print a sketch up drawing in 3d
 
Google sketch up-tutorial
Google sketch up-tutorialGoogle sketch up-tutorial
Google sketch up-tutorial
 
7 types of presentation styles on line
7 types of presentation styles on line7 types of presentation styles on line
7 types of presentation styles on line
 
Design pseudo codeweek 6 2019 -2020
Design pseudo codeweek 6 2019 -2020Design pseudo codeweek 6 2019 -2020
Design pseudo codeweek 6 2019 -2020
 
Php introduction
Php introductionPhp introduction
Php introduction
 

Recently uploaded

The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
ankuprajapati0525
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
addressing modes in computer architecture
addressing modes  in computer architectureaddressing modes  in computer architecture
addressing modes in computer architecture
ShahidSultan24
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
Kamal Acharya
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
MuhammadTufail242431
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
ssuser9bd3ba
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 

Recently uploaded (20)

The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
addressing modes in computer architecture
addressing modes  in computer architectureaddressing modes  in computer architecture
addressing modes in computer architecture
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 

C programming , array 2020

  • 1. C ARRAYS -a collection of same type data, 1D, 2D- www.tenouk.com, © 1/25
  • 2. Agenda 1- Warm up Listen to this video about motivating programmers 5 min 2- ppt teacher demonstrate about Arrays in C programming 25 min 3- Video about how we can use c programming in real life projects , automation and solving problems 3 min 4- Students play or act a game about simulating loops 10 min 5- practical work using lap tops through code blocks in implement a small program work in pairs 10 min 6- use netacade.com to self learn C and get certificate from CISCO 5 m 7- Questions and answers 20 min 8-Refelection 5 min 9- Home work
  • 3. LO CS.2.03 - Students should know how to define / declare and initialize arrays and multidimensional arrays types . so they can apply this knowledge during implementation of software application . Lesson plan
  • 4. Warm Up Listen to this video offline Listen to this video on line
  • 5. Essential Question 1- How can you use array in programming?
  • 6. Warm Up Listen to this video offline Listen to this video on line
  • 7. Warm Up Listen to this video offline Listen to this video on line
  • 8. ARRAYS  An array is a collection of elements of the same type that are referenced by a common name.  Compared to the basic data type (int, float & char) it is an aggregate or derived data type.  All the elements of an array occupy a set of contiguous memory locations.  Why need to use array type?  Consider the following issue: "We have a list of 1000 students' marks of an integer type. If using the basic data type (int), we will declare something like the following…" int studMark0, studMark1, studMark2, ..., studMark999; www.tenouk.com, © 2/25
  • 9. ARRAYS  Can you imagine how long we have to write the declaration part by using normal variable declaration? int main(void) { int studMark1, studMark2, studMark3, studMark4, …, …, studMark998, stuMark999, studMark1000; … … return 0; } www.tenouk.com, © 3/25
  • 10. ARRAYS  By using an array, we just declare like this, int studMark[1000];  This will reserve 1000 contiguous memory locations for storing the students’ marks.  Graphically, this can be depicted as in the following figure. www.tenouk.com, © 4/25
  • 11. ARRAYS  This absolutely has simplified our declaration of the variables.  We can use index or subscript to identify each element or location in the memory.  Hence, if we have an index of jIndex, studMark[jIndex] would refer to the jIndexth element in the array of studMark.  For example, studMark[0] will refer to the first element of the array.  Thus by changing the value of jIndex, we could refer to any element in the array.  So, array has simplified our declaration and of course, manipulation of the data. www.tenouk.com, © 5/25
  • 12. ARRAYS One Dimensional Array: Declaration  Dimension refers to the array's size, which is how big the array is.  A single or one dimensional array declaration has the following form, array_element_data_type array_name[array_size];  Here, array_element_data_type define the base type of the array, which is the type of each element in the array.  array_name is any valid C / C++ identifier name that obeys the same rule for the identifier naming.  array_size defines how many elements the array will hold. www.tenouk.com, © 6/25
  • 13. ARRAYS  For example, to declare an array of 30 characters, that construct a people name, we could declare, char cName[30];  Which can be depicted as follows,  In this statement, the array character can store up to 30 characters with the first character occupying location cName[0] and the last character occupying cName[29].  Note that the index runs from 0 to 29. In C, an index always starts from 0 and ends with array's (size-1).  So, take note the difference between the array size and subscript/index terms. www.tenouk.com, © 7/25
  • 14. ARRAYS  Examples of the one-dimensional array declarations, int xNum[20], yNum[50]; float fPrice[10], fYield; char chLetter[70];  The first example declares two arrays named xNum and yNum of type int. Array xNum can store up to 20 integer numbers while yNum can store up to 50 numbers.  The second line declares the array fPrice of type float. It can store up to 10 floating-point values.  fYield is basic variable which shows array type can be declared together with basic type provided the type is similar.  The third line declares the array chLetter of type char. It can store a string up to 69 characters.  Why 69 instead of 70? Remember, a string has a null terminating character (0) at the end, so we must reserve for it. www.tenouk.com, © 8/25
  • 15. ARRAYS Array Initialization  An array may be initialized at the time of declaration.  Giving initial values to an array.  Initialization of an array may take the following form, type array_name[size] = {a_list_of_value};  For example: int idNum[7] = {1, 2, 3, 4, 5, 6, 7}; float fFloatNum[5] = {5.6, 5.7, 5.8, 5.9, 6.1}; char chVowel[6] = {'a', 'e', 'i', 'o', 'u', '0'};  The first line declares an integer array idNum and it immediately assigns the values 1, 2, 3, ..., 7 to idNum[0], idNum[1], idNum[2],..., idNum[6] respectively.  The second line assigns the values 5.6 to fFloatNum[0], 5.7 to fFloatNum[1], and so on.  Similarly the third line assigns the characters 'a' to chVowel[0], 'e' to chVowel[1], and so on. Note again, for characters we must use the single apostrophe/quote (') to enclose them.  Also, the last character in chVowel is NULL character ('0'). www.tenouk.com, © 9/25
  • 16. ARRAYS  Initialization of an array of type char for holding strings may take the following form, char array_name[size] = "string_lateral_constant";  For example, the array chVowel in the previous example could have been written more compactly as follows, char chVowel[6] = "aeiou";  When the value assigned to a character array is a string (which must be enclosed in double quotes), the compiler automatically supplies the NULL character but we still have to reserve one extra place for the NULL.  For unsized array (variable sized), we can declare as follow, char chName[ ] = "Mr. Dracula";  C compiler automatically creates an array which is big enough to hold all the initializer. www.tenouk.com, © 16/25
  • 17. ARRAYS  Arrays allow programmers to group related items of the same data type in one variable.  However, when referring to an array, one has to specify not only the array or variable name but also the index number of interest.  Program example 1: Sum of array’s element.  Notice the array's element which is not initialized is set to 0 automatically. www.tenouk.com, © 17/25
  • 18. ARRAYS  Program example 2: Searching the smallest value.  Finding the smallest element in the array named fSmallest.  First, it assumes that the smallest value is in fSmallest[0] and assigns it to the variable nSmall.  Then it compares nSmall with the rest of the values in fSmallest, one at a time.  When an element is smaller than the current value contained in nSmall, it is assigned to nSmall. The process finally places the smallest array element in nSmall. www.tenouk.com, © 18/25
  • 19. ARRAYS  Program example 3: Searching the biggest value. By modifying the previous example we can search the biggest value. www.tenouk.com, © 19/25
  • 20. ARRAYS  Program example 5: Storing and reading a string www.tenouk.com, © 20/25
  • 21. ARRAYS  Program example 6: Storing and reading array content and its index www.tenouk.com, © 21/25
  • 22. ARRAYS Two Dimensional/2D Arrays  A two dimensional array has two subscripts/indexes.  The first subscript refers to the row, and the second, to the column.  Its declaration has the following form, data_type array_name[1st dimension size][2nd dimension size];  For examples, int xInteger[3][4]; float matrixNum[20][25];  The first line declares xInteger as an integer array with 3 rows and 4 columns.  Second line declares a matrixNum as a floating-point array with 20 rows and 25 columns. www.tenouk.com, © 22/25
  • 23. ARRAYS  If we assign initial string values for the 2D array it will look something like the following, char Name[6][10] = {"Mr. Bean", "Mr. Bush", "Nicole", "Kidman", "Arnold", "Jodie"};  Here, we can initialize the array with 6 strings, each with maximum 9 characters long.  If depicted in rows and columns it will look something like the following and can be considered as contiguous arrangement in the memory. www.tenouk.com, © 23/25
  • 24. ARRAYS  Take note that for strings the null character (0) still needed.  From the shaded square area of the figure we can determine the size of the array.  For an array Name[6][10], the array size is 6 x 10 = 60 and equal to the number of the colored square. In general, for array_name[x][y];  The array size is = First index x second index = xy.  This also true for other array dimension, for example three dimensional array, array_name[x][y][z]; => First index x second index x third index = xyz  For example, ThreeDimArray[2][4][7] = 2 x 4 x 7 = 56.  And if you want to illustrate the 3D array, it could be a cube with wide, long and height dimensions. www.tenouk.com, © 24/25
  • 25. ARRAYS  Program example 7: Storing and reading array content and its index www.tenouk.com, © 20/25
  • 26. ARRAYS  Program example 8: Swapping iIndex (iRow) with jIndex (iColumn) in the previous program example www.tenouk.com, © 26/25
  • 27. ARRAYS 1. Program example 9: Strings are read in by the rows. 2. Each row will have one string. Enter the following data: “you”, “are”, “cat” for the following example. 3. Remember that after each string, a null character is added. 4. We are reading in strings but printing out only characters. www.tenouk.com, © 22/25
  • 28. ARRAYS  The contents of the array in memory after the three strings are read in the array.  Re-run the program, enter the following data: “you”, “my”. Illustrates the content as done previously. www.tenouk.com, © 23/25
  • 29. ARRAYS 1. Does your output agree? 2. How is the null character, '0' printed? 3. Is there a garbage character in a[1][3]? If so, why? a) The output matched, except the garbage. b) Just an empty space. c) Yes. This slot has been reserved but not filled so whatever the previous data that has been stored here would be displayed (if possible). www.tenouk.com, © 24/25
  • 31. practical work using lap tops through code blocks in implement a C small program work in pairs 210 min
  • 32. Use netacade.com to self learn C and get certificate from CISCO 7 7 min
  • 34. Reflection 5 min • What is your goal to accomplish in next week End Using C programming Language ?
  • 35.
  • 36. students create in small groups a c program related to their capstone project . Home work + = C program Arduino Arduino hardware controller components of irradiation system
  • 37. Home work Discuss how to use Arrays in coding different programs in a video by using office mix. 37
  • 38. Resources watch a video that explain different ways for Arrays and read in the following links : https://www.youtube.com/watch?v =Rtww83GH0BU 38
  • 39. Thank you Collected by Eng.Osama Grace

Editor's Notes

  1. But don’t hide behind your slides.