I've got an assignment for programming class, where I must create an NxN array filled with random numbers between 10 and 99. Print on screen and then rotate it by 90 degree and print again.
Basically this is what I need:
Original:
1 2 3
4 5 6
7 8 9
Rotated
7 4 1
8 5 2
9 6 3
I have no problems creating the original array. But I can't figure out how to rotate it.
Here is what I've got so far:
#include <cstdlib>
#include <iostream>
#include <ctime>
using namespace std;
void Init_Array (int *a, int N, int M)
{
for(int i=0; i<N*N; i++)
*(a+i) = rand()%(99-10)+10;
}
void Print_Array(int *a, int N, int M)
{
for(int i=0; i<N*N; i++)
{
cout << *(a+i) << " ";
if ((i+1)%N==0) cout << endl;
}
cout << endl;
}
int main()
{
time_t t;
srand((unsigned) time(&t));
const int N=3;
const int M=3;
int a[N][M];
Init_Array(*a,N,M);
cout << "Original Array: " << endl;
cout << endl;
Print_Array(*a,N,M);
cout << endl;
cout << "Rotated Array: " << endl;
cout << endl;
//Place holder for rotated array
system("pause");
return 0;
}
Help please :(