0% found this document useful (0 votes)
1 views16 pages

Programming - Lec. 5 (Array of Two Dimensions)

The document outlines a lecture for first-year engineering students at Al-Nahrain University on the use of two-dimensional arrays in C++. It includes objectives, examples of array declarations, initialization, and several programming exercises for students to practice. Homework assignments are also provided to reinforce the concepts learned in the lecture.

Uploaded by

Zaid Mustafa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views16 pages

Programming - Lec. 5 (Array of Two Dimensions)

The document outlines a lecture for first-year engineering students at Al-Nahrain University on the use of two-dimensional arrays in C++. It includes objectives, examples of array declarations, initialization, and several programming exercises for students to practice. Homework assignments are also provided to reinforce the concepts learned in the lecture.

Uploaded by

Zaid Mustafa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

‫جامعة النهرين‪/‬كلية الهندسة‬

‫قسم هندسة الطب الحياتي‬

‫‪Array of Two‬‬
‫‪Dimensions‬‬

‫‪Lec-5‬‬

‫‪1st year‬‬
‫‪2nd Semester‬‬

‫‪1‬‬
Objectives

• Learn the student the use of two dimensions arrays used in C++.

• Write several C++ program which use of two dimensions arrays.


Array of Two Dimensions
Array of Two Dimensions

• Arrays can have higher dimension. There can be arrays of two dimension which is array of
arrays. It is accessed with two index. Also there can be arrays of dimension higher than two.
Array of Two Dimensions

• Examples:

int a [10] [10];

int num [3] [4];

float num [3] [4];

char c [4] [2];


Initializing 2D-Array
Elements
Initializing 2D-Array Elements

• a [2] [3] = { {1, 2, 3} , {4, 5, 6} };


Procedure
Procedure
• Example 1: Write C++ program, to read 15 numbers, 5 numbers per row, then
print them:
Procedure
• Example 2: Write C++ program, to read 4*4 2D-array, then find the summation
of the array elements, finally print these elements:
Procedure
• Example 3: Write C++ program, to read 3*4 2D-array, then find the summation
of each row:
Procedure
• Example 4: Write C++ program, to convert 2D-array into 1D-array.
Procedure
• Example 5: Write C++ program, to replace each element in the main diameter
(diagonal) with zero.
Procedure
• Example 5: Write C++ program, to replace each element in the main diameter
(diagonal) with zero.
Homework and
Assignment
Homework and Assignment

1. Write C++ program, to read 3*4 2D-array, then replace each value equal 5 with 0.

2. Write C++ program, to addition two 3*4 arrays.

3. Write C++ program, print the square root of an array.

4. Write C++ program, to find the greatest number in the second diagonal, in 3*3
array.

5. Write C++ program, to read X[ n ], and rotate the elements to the left by one
position.

You might also like