|
Home ► Lab Exercise ► Object Oriented Programming Lab Exercise Programs ► CPP Program For Matrix Addition▼
CPP Program For Matrix Addition |
Alogarithm steps:
- Start the program
- Create the class
- Declare the data member as array and member function
- Get the input and store it in an array
- Create the object for the class
- Call the function by using of the object
- The function perform the operation using the array data members
- Compile and execute the program
CPP Program For Matrix Addition
#include
class matrix
{
int a[2][2], b[2][2], c[2][2];
void add()
{
cout<<”Enter the A matrix:”<<”\n”;
for(int i=0; i<2; i++)
{
for(int j=0; j<2; j++)
{
cin>>a[i][j];
}
}
cout<<”Enter the B matrix:”<<”\n”;
for(int i=0; i<2; i++)
{
for (int j=0; j<2; j++)
{
cin>>b[i][j];
}
}
for( i = 0; i< 2; i++)
{
for( j = 0; j<2; j++)
{
c[i][j] = a[i][j] + b[i][j];
}
}
cout<<”Addition of Two matrixes:”<
SAMPLE INPUT AND OUTPUT:
Enter the A matrix:
1 1
1 1
Enter the B matrix:
2 2
2 2
Addition of Two matrixes:
3 3
3 3
|
|
⇓ Student Projects ⇓
⇑ Student Projects ⇑
|