Professional Documents
Culture Documents
Arrays
Programming Fundamentals • Variables we declared in our earlier programs can
store a single data item of the specified type
• We can have a variable that stores an integer or a
variable that stores a character
• An array can store several data items of the same
Arrays & Strings type
• We can have an array of integers, an array of
characters – in fact an array of any type of data
Arrays Arrays
• For example: We can store 5 values of type int without
• An Array is a series of elements (variables) of the
having to declare 5 different variables each one with a
same type placed consecutively in memory that can
different identifier
be individually referenced by adding an index to a
• Instead of that, using an array we can store 5 different
unique name values of the same type int with one unique identifier
(variable name)
1
10/30/2017
a = myDataArray[2];
2
10/30/2017
1. Write a program that reads marks of 10 • We can omit the size of the array in the
quizzes from user and displays the average declaration of an array, provided we supply
quiz marks. initializing values
2. Write a program that reads maximum up to • Number of elements in the array will then be
10 quiz marks from user and displays the same as the initializing values
average quiz marks. • For example,
int values[] = {2,3,4};
int values [] = {1,2,3,4,5}; Note: use single loop to calculate above and
below the average
Programming Fundamentals- Arrays & 15 Programming Fundamentals- Arrays & 16
Strings Strings