



















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




















.
.
Outline 6.1 Introduction 6.2 Arrays 6.3 Declaring Arrays 6.4 Examples Using Arrays
.
6.1 Introduction
Data Structures : “In computer science, a data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently” (NIST)
.
Arrays
.
6.2 Arrays
Namethat ofall array elements (Note of this array have the same name, c)
Positionthe element number within of array c
c[6]
0 62
1 6453 78
c[0] c[1] c[2] c[3]
c[11]
c[10]
c[9]
c[8]
c[7]
c[5]
c[4]
.
6.3 Defining Arrays
.
Array indexing
.
Array indexing
int age[10]; Accessing 5 th^ element of the array c=age[3+2]; OR i=2; c=age[i+3];
.
Example1: Using Arrays
.
Example 2
int totalAge = 0 ; int age[10]; for ( i = 0 ; i < 10 ; i ++ ) { totalAge + = age [ i ] ; }
Outline
.
16
Program Output
Element 0 Value 0 (^12 ) (^34 ) (^56 ) (^78 ) 9 0
.
Copying Arrays
.
Example: 4
.
Example 5
Search a number z in an array
for ( i =0 ; i < 100 ; i ++ ) { if ( z == a [ i ] ) { found = 1 ; break ; } } if ( found == 1 ) printf( “ We found the integer at position %d” ,i) ; else printf( “ The number was not found” );