Below is some code to create and print a 10 X 10 matrix. The code is incomplete,
ID: 3578473 • Letter: B
Question
Below is some code to create and print a 10 X 10 matrix. The code is incomplete, you will have to complete the code to do the following:
Every cell in the 10 X 10 matrix should be set to 0 (zero), except for the edges. The edges should be set to 1 (one) – You can think of a picture frame. Here is an example of what the outcome should look like; i.e., what the code needs to do:
1 1 1 1 1 1 1 1 1 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 1 1 1 1 1 1 1 1 1
Modify the below code as necessary. Replace X, Y, M, N, Q, & P with the appropriate code. I have solved for X.
Your answer should solve for Y, M, N, Q, & P...
#include <iostream>
using namespace std;
//
// This program will create a 10 X 10 matrix.
// All matrix 'cells' will be 0, except for
// the boarder:
//
int main(int argc, char* argv[])
{
const int SIZE = 10;
int matrix[SIZE][SIZE];
//
// Populate the matrix
//
for (int i = 0; i < SIZE; i++){
for (int j = 0; j < SIZE; j++ ){
//
// create top and bottom boarder
//
if (i == X || i == Y){
matrix[i][j] = 1;
}
//
// create left and right boarder
//
else if (j == M || j == N){
matrix[i][j] = 1;
}
//
// otherwise
//
else {
matrix[i][j] = 0;
}
}
}
//
// print out the matrix
//
for (int i = 0; i < Q; i++){
for (int j = 0; j < P; j++ ){
cout << matrix[i][j] << " ";
}
cout << endl;
}
return 0;
}
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Here is the answer for X. Please include your answers for Y, M, N, Q, & P on separate lines
x = 0
Explanation / Answer
Answer :
X=0
Y=9
M=0
N=9
Q=SIZE=10
P=SIZE=10
Programme with above values :
#include <iostream>
using namespace std;
//
// This program will create a 10 X 10 matrix.
// All matrix 'cells' will be 0, except for
// the boarder:
//
int main(int argc, char* argv[])
{
const int SIZE = 10;
int matrix[SIZE][SIZE];
//
// Populate the matrix
//
for (int i = 0; i < SIZE; i++){
for (int j = 0; j < SIZE; j++ ){
//
// create top and bottom boarder
//
if (i == 0 || i == 9){
matrix[i][j] = 1;
}
//
// create left and right boarder
//
else if (j == 0 || j == 9){
matrix[i][j] = 1;
}
//
// otherwise
//
else {
matrix[i][j] = 0;
}
}
}
//
// print out the matrix
//
for (int i = 0; i < SIZE; i++){
for (int j = 0; j < SIZE; j++ ){
cout << matrix[i][j] << " ";
}
cout << endl;
}
return 0;
}
Output :
1 1 1 1 1 1 1 1 1 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 1 1 1 1 1 1 1 1 1
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.