Sie sind auf Seite 1von 50

Lecture-06

Arrays

Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST


Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
 Linear search
 Binary search

Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST


Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
 Arrays in C can have multiple subscripts / multidimensional array
 Is to represent tables of values consisting of information arranged in rows and columns.

 The first (by convention) identifies the element’s row and the second (by
convention) identifies the element’s column.

 The array contains three rows and four columns, so it’s said to be a 3-by-4 array.

 In general, an array with m rows and n columns is called an m-by-n array.

Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST


Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
 A multiple-subscripted array can be initialized when it’s defined, much like a
single subscripted array.

 If there are not enough initializers for a given row, the remaining elements of that
row are initialized to 0.

Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST


Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
 When we receive a single-subscripted array as a parameter, the array brackets are
empty in the function’s parameter list.
 The first subscript of a multiple-subscripted array is not required either, but all
subsequent subscripts are required.

Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST


 The following nested for statement determines the total of all the elements in array
a.

Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST


Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST
 Write statements to accomplish each of the following
a) Display the value of the seventh element of character array f.
b) Input a value into element 4 of single-subscripted floating-point array b.
c) Initialize each of the five elements of single-subscripted integer array g to 8.
d) Total the elements of floating-point array c of 100 elements.
e) Copy array a into the first portion of array b. Assume double a[11], b[34];
f) Determine and print the smallest and largest values contained in 99-element floating
point array w.

Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST


 Consider a 2-by-5 integer array t
a) Write a nested for statement that initializes each element of t to zero.
b) Write a statement that inputs the values for the elements of t from the terminal.
c) Write a series of statements that determine and print the smallest value in array t.
d) Write a statement that displays the elements of the first row of t.
e) Write a statement that totals the elements of the fourth column of t.
f) Write a series of statements that print the array t in tabular format. List the column
subscripts as headings across the top and list the row subscripts at the left of each row.

Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST


 Introduction to C programming, Chapter-6 from text book.

Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST


Engr. Asim Javaid, Lecturer, Department of Software Engineering, MUST

Das könnte Ihnen auch gefallen