SlideShare a Scribd company logo
1 of 39
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 (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

Similar to C programming , array 2020 (20)

cprogrammingarrayaggregatetype.ppt
cprogrammingarrayaggregatetype.pptcprogrammingarrayaggregatetype.ppt
cprogrammingarrayaggregatetype.ppt
 
cprogrammingarrayaggregatetype.ppt
cprogrammingarrayaggregatetype.pptcprogrammingarrayaggregatetype.ppt
cprogrammingarrayaggregatetype.ppt
 
cprogrammingarrayaggregatetype.ppt
cprogrammingarrayaggregatetype.pptcprogrammingarrayaggregatetype.ppt
cprogrammingarrayaggregatetype.ppt
 
cprogrammingarrayaggregatetype (1).ppt
cprogrammingarrayaggregatetype (1).pptcprogrammingarrayaggregatetype (1).ppt
cprogrammingarrayaggregatetype (1).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.pptOsama 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 mansourOsama 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 ghandourOsama 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 10Osama 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 ghandourOsama 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 ghandourOsama 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 operatorsOsama 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 osamaOsama 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 ghandourOsama 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 3dOsama 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 lineOsama Ghandour Geris
 
Design pseudo codeweek 6 2019 -2020
Design pseudo codeweek 6 2019 -2020Design pseudo codeweek 6 2019 -2020
Design pseudo codeweek 6 2019 -2020Osama 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

Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture designssuser87fa0c1
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIkoyaldeepu123
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 

Recently uploaded (20)

Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture design
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AI
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 

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.