### How to square a matrix

I have the code which creates the matrix, but I am having trouble squaring the matrix I have created.
It would be easier to help if you post the code and tell us what trouble are you having.
void display (int nums[ROWS][COLS])
{
int rownum, colnum;
for ( rownum = 0; rownum < ROWS; rownum++)
{
for (colnum = 0; colnum < COLS; colnum++){
cout << setw(5) << nums [rownum][colnum];}

cout << setw(5) << nums[rownum][colnum];
cout << endl;
}
return;
}
int main ()
{
int M [ROWS][COLS];
cout << "Enter in 9 elements for a 3x3 matrix." << endl;
cin >> M[0][0] >> M[0][1] >> M[0][2] >> M[1][0] >> M[1][1] >> M[1][2] >> M[2][0] >> M[2][1] >> M[2][2];
return 0;
}
Sorry, that is my code.
First, please use code tags when posting code. See http://www.cplusplus.com/articles/jEywvCM9/

Is that really your entire code?

What does "to square a matrix" mean?
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364`` ``````#include #include #include using namespace std; double x; double y; double x_comp; double y_comp; double angle; const int ROWS = 3; const int COLS = 3; void display (int [ROWS][COLS]); vectorRot() { } squaredMatrix() { } void display (int nums[ROWS][COLS]) { int rownum, colnum; for ( rownum = 0; rownum < ROWS; rownum++) { for (colnum = 0; colnum < COLS; colnum++){ cout << setw(5) << nums [rownum][colnum];} cout << setw(5) << nums[rownum][colnum]; cout << endl; } return; } matrixDisplay() { } int main () { cout << "Enter a value for x." << endl; cin >> x; cout << "Enter a value for y." << endl; cin >> y; cout << "Enter a value for the angle of rotation." << endl; cin >> angle; x_comp = (x*cos(angle) + (y*sin(angle))); y_comp = (y*-sin(angle) + (y*cos(angle))); cout << "The resulting vector has a x component of " << x_comp << endl; cout << "The resulting vector has a y component of " << y_comp << endl; int M [ROWS][COLS]; cout << "Enter in 9 elements for a 3x3 matrix." << endl; cin >> M[0][0] >> M[0][1] >> M[0][2] >> M[1][0] >> M[1][1] >> M[1][2] >> M[2][0] >> M[2][1] >> M[2][2]; return 0; }``````
This is my whole code. Sorry, I'm new here haha. Anyway, I have just started programming and I am having difficulties.
and squaring a matrix just means to multiply a matrix by itself.
How does one multiply two matrices? (In math.)
Topic archived. No new replies allowed.