0% found this document useful (0 votes)
40 views3 pages

5x6 Matrix

The document contains code for initializing and printing out 2D arrays (matrices) of different sizes in C++. The first matrix is 5x6, the second is 6x2, and the third is also 6x2 but prints the total number of elements. Each code sample initializes the matrix with values, then uses nested for loops to print out each element.

Uploaded by

aimen
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)
40 views3 pages

5x6 Matrix

The document contains code for initializing and printing out 2D arrays (matrices) of different sizes in C++. The first matrix is 5x6, the second is 6x2, and the third is also 6x2 but prints the total number of elements. Each code sample initializes the matrix with values, then uses nested for loops to print out each element.

Uploaded by

aimen
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

5x6 Matrix

#include<iostream>
using namespace std;
int main()
{
int matrix[5][6] = { {22,2,3,5,7,12},{13,4,8,9,32,1},{19,7,4,10,17,18},
{8,19,20,27,30,41},{5,22,38,45,53,64} };
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 6; j++)
{
cout << matrix[i][j] <<"\t"<< endl;
}
cout << endl;
}
}

6x2
#include<iostream>
using namespace std;
int main()
{
int matrix[6][2] = { {12,12},{54,34},{16,3},{12,6},{43,23},{1,2} };
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 2; j++)
{
cout << matrix[i][j] << endl;
}
}
cout << endl;
system("pause");
return 0;
}

#include<iostream>
using namespace std;
int main()
{
int matrix[6][2] = { {12,2},{54,34},{16,3},{12,6},{43,23},{1,2} };
int i = 0, j = 0;
int elements = 0;
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 2; j++)
{
cout << matrix[i][j];
elements++;
}
cout << endl;
}
cout << "num of elements=" << elements << endl;
}

You might also like