1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>
using namespace std;
int main ()
{
int i, j, number, row1, row2, column1, column2;
int matrixA[7][7] = {{2,5,6,3,5,9,1},{3,0,8,5,6,1,2},{6,4,9,6,5,2,3},
{1,-4,2,5,1,0,4},{4,9,6,2,2,7,5},{7,1,6,9,8,9,6},
{-2,-3,-4,5,-6,-7,7}};
int matrixB [7][7] = {0};
int sum[7][7] = {0};
//Section 1
cout << "Section #1 : Displaying the matrix\n\n";
//displays the matrix ;array on screen
for(i=0; i<7; ++i)
{
for(j=0; j<7; ++j)
{
cout << setw(6) << matrixA[i][j];
}
cout << "\n";
}
//Section 2
// asks for user to input the number they wish to add to the cells
cout << "\n\nSection #2 : Get input from the user\n\n" << " Enter the number you would like to add : ";
cin >> number;
cout << endl;
// asks user for the starting cell
cout << " Enter the starting cell\n" << " Row : ";
cin >> row1;
cout << " Column : ";
cin >> column1;
cout << "\n Enter the ending cell\n" << " Row : ";
cin >> row2;
cout << " Column : ";
cin >> column2;
// creating new matrix
while( row1<row2)
{
matrixB[row1][column1] = number;
++row1;
while(column1<=column2)
{
matrixB[row1][column1] = number;
++column1;
}
}
// displays matrixB
for(i=0; i<7; ++i)
{
for(j=0; j<7; ++j)
{
cout << setw(6) << matrixB[i][j];
}
cout << "\n";
}
//Section 3
cout << "\n\nSection #3 : Displaying new matrix\n\n";
//Adds the matrices
sum[7][7]=matrixA[7][7]+matrixB[7][7];
//displays the new matrix
for(i=0; i<7; ++i)
{
for(j=0; j<7; ++j)
{
cout << setw(6) << sum[i][j];
}
cout << "\n";
}
}
|