Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  


Shop
CPP All : Two dimensional arrays and Matrices
Concept Learning Code Sheets

Student Marks 3 Subjects 2D Array #1618

Showing how multiple students marks in multiple subjects can be stored and used in 2D Array.

#include
#include
using namespace std;
int main()
{
int M[2][3]={{47,75,80},{52,81,76}};
int p;
for ( int i = 0; i < 2; i++ )
{
p=0;
for ( int j = 0; j < 3; j++ )
{
p+=M[i][j];
}
float pm=(float) p/3;
cout< cout<<"% Marks Student"< }
return 0;
}

Matrix addition 2D with pre-initialised values #1635

Adding two 2D integer matrix into a third matrix of same size with values pre-initialised at the beginning.

#include
using namespace std;
int main()
{
int A[2][3]={{1,2,3},{4,5,6}};
int B[2][3]={{7,8,9},{10,11,12}};
int C[2][3];
for(int i=0 ; i<2 ; i++ )
{
for(int j=0; j<3; j++ )
{
C[i][j]=A[i][j]+B[i][j];
}
}
for(int i=0 ; i<2 ; i++ )
{
for(int j=0; j<3; j++ )
{
cout< }
cout< }
return 0;
}

Displaying a 2D Array #1887

Displaying a 2 dimensional array which is pre-filled with initialised data in the row column format.

#include
using namespace std;
int main()
{
int arr[2][3]={{47,75,80},{52,81,76}};
for(int i = 0; i < 2; i++ )
{
for(int j = 0; j < 3; j++ )
{
cout< }
cout< }
return 0;
}

Sum of all members of 2D array #1889

Finding the sum of all members of a matrix having number values.

#include
using namespace std;
int main()
{
int M[2][3]={{47,75,80},{52,81,76}};
int sum=0;
for (int i = 0; i < 2; i++ )
{
for(int j = 0; j < 3; j++ )
{
sum+=M[i][j];
}
}
cout<<"Sum of all members = "< return 0;
}

Sum of each row and all members of 2D array #1891

Finding the sum of each row and all members of a matrix having number values.

#include
using namespace std;
int main()
{
int M[2][3]={{47,75,80},{52,81,76}};
int sum=0,sumr=0;
for (int i = 0; i < 2; i++ )
{
sumr=0;
for(int j = 0; j < 3; j++ )
{
sum+=M[i][j];
sumr+=M[i][j];
}
cout<<"Sum of row "< }
cout<<"sum of all members = "< return 0;
}

Sum of each row and row addition of 2D array #1893

Finding the sum of each row and then sum of all members by adding each row addition of a matrix having number values.

#include
using namespace std;
int main()
{
int M[2][3]={{47,75,80},{52,81,76}};
int sumr=0,sum=0;
for (int i = 0; i < 2; i++ )
{
sumr=0;
for(int j = 0; j < 3; j++ )
{
sumr+=M[i][j];
}
sum+=sumr;
cout<<"Sum of row "< }
cout<<"sum of all members = "< return 0;
}

Print square of a 2D array in row-column format #1895

Printing a 2D matrix with each value squared in a proper rows and column format that looks like a matrix.

#include
using namespace std;
int main()
{
int M[3][2]={{1,2},{3,4},{5,6}};
for (int i = 0; i < 3; i++ )
{
for(int j = 0; j < 2; j++ )
{
cout< }
cout< }
return 0;
}
Solved Problems

Product of single 2D matrix members #2229

Write a program to find the product of all members of any 2D Matrix whose siz

Search in 2D Array #2325

Write a program to search the presence of user given input number in a 2 dim


Code Sheets:7  Solved Problems:2 
Back