0

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 :(

  • 1
    `for(int i=0; i – shuttle87 Nov 19 '15 at 16:10
  • Thanks. Forgot to change that, but still it doesn't help me in roating the array :( – Karalis Artūrs Nov 19 '15 at 16:17
  • Have you worked out an algorithm for rotating the array yet? If so, why don't you tell us what it is? If not, why didn't you ask us about an algorithm for rotating an array? It seems like you didn't put any effort into thinking about what your question actually was. – David Schwartz Nov 19 '15 at 18:04

0 Answers0