How to rotate a matrix[m][m] 270 degrees!

Dec 21, 2012 at 6:11pm
Hi everyone,im new here in this forum and i need help from you guys.

I need to write a program in C++,to create an matrix[m][m], for m=8.
The values of the diagonal must be fill from the vector yourbirth[m],which contains my birthday(15.05.1994),and the other values should be fill like in the foto below(matrix a).And if the amount of the vector is number "couple number" i must rotate the matrix for 270 degrees,else if the number is not "couple number" but "to"(or how is it called coz iam not so good in english),i must rotate the matrix for 90 degrees.In the end i must print both matrixe's.The one which is created in start and the rotated one.Please some one create it for me,i really need help.

The image:
http://i49.tinypic.com/27ymr0m.jpg
Dec 21, 2012 at 6:58pm
Sadly, nobody is going to write it for you...
When rotating 90 degrees, matrix[i][j] is moved to matrix90[m-1-j][i] and when rotating 270 degrees, it is sent to matrix270[j][m-1-i]. That should be enough. If you still can't do it, ask very specific questions.
Dec 21, 2012 at 7:11pm
Thanks for the answer,i wrote the code for the original matrix,but i dont know where to write the code to rotate the matrix,and then to print both of them? Could you please just edit the code and do it ?




#include <iostream>
#include<iomanip>
using namespace std;

int main()
{
const int m=8;
int i,j,matrica[m][m],datelindja[m]={1,5,0,5,1,9,9,4};
double s=0;


for(i=0;i<m;i++)

for(j=0;j<m;j++)

if(i<j)
matrica[i][j]=i+j;

else
if(i==j)
{
matrica[i][j]=datelindja[i];
s=s+matrica[i][j];
}
else

matrica[i][j]=i-j;

cout<<"Matrica e formuar"<<endl;


for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
cout.width(4);
cout<<matrica[i][j];
}
cout<<endl;
}


return 0;
}
Dec 21, 2012 at 10:30pm
Could you please just edit the code and do it ?
This is not how things work. Lines like that are only asking for ridicule...

You should either declare another matrix array and put the values in it using the code I gave you or just use that code to print the matrix right away. To clarify, element at [m-1-j][i] is the one which would be in position [i][j] after a rotation. To work with a matrix as if it was rotated, replace the latter kind of index with the former.
Topic archived. No new replies allowed.