You are on page 1of 4

1

Assignment.3

Submitted by:
Muhammad Adnan Maqbool, (BSCE02203138)

Section:
C. (2nd Semester)

Subject: COMPUTER PROGRAMMING

Topic:
Function

Date: 28/05/2021

Submitted to:
Pro. Muhammad Shahzad.

University of Lahore Civil Engineering Department

ADNAN DOCS.
2

”In the Name of Allah, the most

Beneficent, the most Merciful"

ADNAN DOCS.
3

Q1:
In C++ Two-Dimensional array in C++ is an array that consists of more than one rows and
more than one column. In 2-D array each element is refer by two indexes. Elements stored
in these Arrays in the form of matrices. The first index shows a row of the matrix and the
second index shows the column of the matrix. A two-dimensional array is also called
a matrix. A two-dimensional array in C++ is the simplest form of a multi-
dimensional array. It can be visualized as an array of arrays.
The 2D array is organized as matrices which can be represented as the collection of rows
and columns. However, 2D arrays are created to implement a relational database lookalike
data structure. It provides ease of holding the bulk of data at once which can be passed to
any number of functions wherever required.

Q2:
A 2D array is stored in the computer's memory one row following another. ... If each data
value of the array requires B bytes of memory, and if the array has C columns, then
the memory location of an element such as score[m][n] is (m*c+n)*B from the address of
the first byte.
A 2D array’s elements are stored in continuous memory locations. It can be represented in
memory using any of the following two ways:

1. Column-Major Order
2. Row-Major Order

1. Column-Major Order:
In this method the elements are stored column wise, i.e. m elements of first column are
stored in first m locations, m elements of second column are stored in next m locations and
so on
2. Row-Major Order:
In this method the elements are stored row wise, i.e. n elements of first row are stored
in first n locations, n elements of second row are stored in next n locations and so on

Q3:

Syntax of Two-Dimensional Array:-

(Data type) (Name of array) [Number of rows] [Number of columns];

For example:-

Int matrix [7] [7];


When we type the above statement the compiler will generate a 2-D array of a matrix
which consists of 7 rows and 7 columns.

// C++ Program to print the elements of a

ADNAN DOCS.
4

// Two-Dimensional array
#include<iostream>
using namespace std;

int main()
{
// an array with 3 rows and 2 columns.
int x[3][2] = {{0,1}, {2,3}, {4,5}};

// output each array element's value


for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 2; j++)
{
cout << "Element at x[" << i
<< "][" << j << "]: ";
cout << x[i][j]<<endl;
}
}

return 0;
}

The End

ADNAN DOCS.

You might also like