154. Write a function that rotates and MxN matrix......
Microsoft Interview Questions and Answers
(Continued from previous question...)
154. Write a function that rotates and MxN matrix......
Question:
Write a function that rotates and MxN matrix. Even though the matrix is MxN, you are given it in the form of a 1 dimensional array.
int[] Rotate(int[] arr, numRows, numCols)
Does not need to be in place.
maybe an answer:
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
int main()
{
int m,n;
cin>>m>>n;
int array[m*n+1];
int array1[m*n+1];
for(int i=1;i<=m*n;i++)
cin>>array[i];
int q,r;
for(int i=1;i<=m*n;i++)
{
q=(int)ceil((double)i/n);
r=i%n;
if(r==0)
r=n;
array1[(r-1)*m+q]=array[i];
}
cout<<"\n\n";
for(int i=1;i<=m*n;i++)
cout>>array1[i]>>" ";
getch();
}
(Continued on next question...)
Other Interview Questions
|