#include <iostream>
#include <iomanip>
using namespace std;
void inputData(float A[][3],int numberOfRows);
void calcRowTotal(float A[][3], float B[][3], float C[][1], int numberOfRows);
void copyMatrix(float A[][3], float B[][3], int numberOfRows);
void print(float A[][3],float B[][3],float C[][3], int numberOfRows);
int main()
{
 float A[3][3], B[3][3],C[3][1],C1[3][3];
 inputData(A,3);
 copyMatrix(A,B,3);
 calcRowTotal(A,B,C,3);
 print(A,B,C1,3);
 return 0;
}
void inputData(float A[][3],int numberOfRows)
{
 for(int i=0; i<numberOfRows; i++)
  for(int j=0; j<3; j++)
  {
   cout << "Enter Data " << i+1 << "," << j+1 << " : ";
   cin >> A[i][j];
  }
}
void copyMatrix(float A[][3], float B[][3], int numberOfRows)
{
 for (int i=0; i<numberOfRows; i++)
  for(int j=0; j<3; j++)
   B[i][j] = A[i][j];
}
void calcRowTotal(float A[][3], float B[][3], float C[][1], int numberOfRows)
{
 for (int i=0; i<numberOfRows; i++)
  C[i][1] = A[i][0]+A[i][1]+A[i][2]+B[i][0]+B[i][1]+B[i][2];
 cout << setw(9) << "Matrix1" << setw(20) << "Matrix2" << setw(20) << "Result\n";
 for (int i=0; i<numberOfRows; i++)
 {
  for (int j=0; j<3; j++)
   cout << setw(3) << A[i][j];
  cout << setw(11) << " ";
  for(int j=0; j<3; j++)
   cout << setw(3) << B[i][j];
  cout << setw(17) << C[i][1] << endl;
 }
 
}
void print(float A[][3],float B[][3],float C[][3], int numberOfRows)
{
 for (int i=0; i<numberOfRows; i++)
  for (int j=0; j<3; j++)
   C[i][j] = A[i][j]+B[i][j];
 cout << endl << setw(9) << "Matrix1" << setw(20) << "Matrix2" << setw(20) << "Result\n";
        for (int i=0; i<numberOfRows; i++)
        {
                for (int j=0; j<3; j++)
                        cout << setw(3) << A[i][j];
                cout << setw(11) << " ";
                for(int j=0; j<3; j++)
                        cout << setw(3) << B[i][j];
  cout << setw(11) << " ";
  for(int j=0; j<3; j++)
   cout << setw(3) << C[i][j];
  cout << endl;
 }
}
 







 
 
 
 
 
 
 
 
 
 
 
 
 
 
 







 Colombo Time
  Colombo Time 
0 comments:
Post a Comment