KEMBAR78
2D Arrays | PDF
0% found this document useful (0 votes)
25 views3 pages

2D Arrays

A two-dimensional array is a table structure consisting of rows and columns, where each element is accessed using two indices. The document provides examples of taking user input, initializing a 2D array, and finding the maximum and minimum values within a 2D array using C++. Syntax and code snippets are included for better understanding.

Uploaded by

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

2D Arrays

A two-dimensional array is a table structure consisting of rows and columns, where each element is accessed using two indices. The document provides examples of taking user input, initializing a 2D array, and finding the maximum and minimum values within a 2D array using C++. Syntax and code snippets are included for better understanding.

Uploaded by

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

Two-Dimensional Array

Two- dimensional array can be considered as a table that consist of rows and columns. Each
element in 2-D array is referred with the help of two indexes. One index is used to indicate the row and
the second index indicates the column of the element.

Syntax

Data-type identifier[row][column];

Int arr[4][3];

0,0 0,1 0,2

1,0 1,1 1,2

2,0 2,1 2,2

3,0 3,1 3,2

0 1 2

1 1.Taking input from user in 2D array:


2 #include<iostream>
3 using namespace std;
int main()
{
int arr[2][4];
for(int i=0;i<2;i++)
for(int j=0;j<4;j++)
{
cout<<"Enter an integer: ";
cin>>arr[i][j];
}
for(int i=0;i<2;i++)
{
for(int j=0;j<4;j++)
cout<<arr[i][j]<<" ";
cout<<endl;
}
return 0;
}

2.Initializing 2D array:
#include<iostream>
using namespace std;
int main()
{
int arr[2][3]={15,21,9,84,33,72};
for(int i=0;i<2;i++)
{
for(int j=0;j<3;j++)
cout<<"arr["<<i<<"]["<<j<<"]= "<<arr[i][j]<<" ";
cout<<endl;
}
return 0;
}

3.Find Maximum & Minimum in 2D array:


#include<iostream>

using namespace std;

int main()

int max,min,arr[2][4]={{15,21,9,84},{33,72,18,47}};
max=min=arr[0][0];

for(int i=0;i<2;i++)

for(int j=0;j<4;j++)

if(arr[i][j]>max)

max=arr[i][j];

if(arr[i][j]<min)

min=arr[i][j];

cout<<"Maximum= "<<max<<endl<<"Minimum= "<<min;

return 0;

You might also like