this is the scenario
A matrix (two-dimensional array) is symmetric if:
it is a square matrix (its sides are equal)
its elements are placed symmetrically about the main diagonal (the diagonal that goes from upper-left to bottom-right vertex)
To be concise - this is a symmetric matrix:
1 2 3
2 1 2
3 2 1
and this is not:
1 2 3
2 1 2
4 2 1
The code presented below declares 4x4 matrix initially filled with some data. Your task is to complete the code and to answer the
fundamental question: is that matrix symmetrical or not.
When you complete your code, play with the matrix a bit:change its dimensions, move some of the elements - be sure that your code
works well in any situation.
(this is the base code)
#include <iostream>
using namespace std;
int main(void) {
double matrix[][4] = { { 1, 2, 3, 4 },
{ 2, 2, 3, 1 },
{ 3, 3, 3, 2 },
{ 4, 1, 2, 4 } };
int side = sizeof(matrix[0]) / sizeof(matrix[0][0]);
bool issymmetric = true;
// Insert your code here
if(issymmetric)
cout << "The matrix is symmetric" << endl;
else
cout << "The matrix is not symmetric" << endl;
return 0;
}
@tojo,
This is your third post ... and you are yet to show any of your own code.
Whilst we've had quite a lot of fun with your previous questions (on palindromes), maybe it's time you showed some of your own efforts?
This is not a homework site. We don't do your homework for you. Pasting an assignment and expecting us to provide an answer will not yield much helpful information.
Start by adding code tags to your post. Before your any code that you paste add the tag [code], and after your code, add the tag [/code]. If you do this, it will make it easier for us to read the code, and make us more willing to help you. The more you try to make our job easier, the more help you are likely to get.
Second, make an attempt at solving the problem yourself. When you run across a problem, ask us about it. For instance:
- It won't compile (and here are the error messages)
- It won't link (and here are the error messages)
- It compiles but it won't run (and any error messages you get)
- It runs, but it doesn't give the correct response (and add the expected and received responses)
Third, break your assignment into steps. Do one step and see what you get. Then do another step and see what you get. Build up until you run into a problem you can ask us about or you finish the assignment. For your first step, just try to print out the 2-d matrix. Make sure you can print out what you think you have. Then print out just the diagonal values. When you can do that, you should have a foundation for solving the rest of the problem.
Edit: As a beginner you might not be able to discriminate between compiler and linker errors. That's ok, just paste your error messages and we can help you figure out what's wrong.
A matrix (two-dimensional array) is symmetric if: 1. it is a square matrix (its sides are equal) 2. its elements are placed symmetrically about the main diagonal (the diagonal that goes from upper-left to bottom-right vertex)
The first part should be almost easy.
(The code you were given is <unspeakable>.)
Given code below: