#include #include using namespace std; // Global variables const int MAX_ROWS = 50; const int MAX_COLS = 50; // Notice that function prototypes need not include the variable names. void read_matrix( double [MAX_ROWS][MAX_COLS], int&, int& ); void prnt_matrix( double [MAX_ROWS][MAX_COLS], int, int, short ); void lin_comb( double [MAX_ROWS][MAX_COLS], double [MAX_ROWS][MAX_COLS], double [MAX_ROWS][MAX_COLS], double, double, int, int ); int main() { double A[MAX_ROWS][MAX_COLS], B[MAX_ROWS][MAX_COLS], C[MAX_ROWS][MAX_COLS]; int rowsA, colsA, rowsB, colsB; cout << "First matrix...\n"; read_matrix( A, rowsA, colsA ); cout << "\n"; cout << "Second matrix...\n"; read_matrix( B, rowsB, colsB ); cout << "\n"; if ( rowsA == rowsB && colsA == colsB ) { lin_comb( A, B, C, 2, -3, rowsA, colsA ); prnt_matrix( C, rowsA, colsA, 8 ); } else { cout << "Dimension mismatch - Addition not defined.\n"; } cout << "\n\n"; system( "PAUSE" ); return( EXIT_SUCCESS ); } void read_matrix( double array[MAX_ROWS][MAX_COLS], int &rows, int &cols ) { cout << "Enter the number of rows and columns.\n" << "# of Rows = "; cin >> rows; cout << "# of Columns = "; cin >> cols; cout << endl; for ( int i = 0; i < rows; i++ ) { for ( int j = 0; j < cols; j++ ) { cout << "Entry [" << i << "][" << j << "] = "; cin >> array[i][j]; } } } #include void prnt_matrix( double array[MAX_ROWS][MAX_COLS], int rows, int cols, short prt_width ) { cout << setiosflags( ios::left ); for ( int i = 0; i < rows; i++ ) { for ( int j = 0; j < cols; j++ ) { cout << setw( prt_width ) << array[i][j] << " "; } cout << "\n"; } } void lin_comb( double array1[MAX_ROWS][MAX_COLS], double array2[MAX_ROWS][MAX_COLS], double array3[MAX_ROWS][MAX_COLS], double c1, double c2, int rows, int cols ) { for ( int i = 0; i < rows; i++ ) { for ( int j = 0; j < cols; j++ ) { array3[i][j] = c1 * array1[i][j] + c2 * array2[i][j]; } } }