Coders Packet

Rotate Image (N*N Array) Using C++

By Ravi Kumar Mehta

We can consider the image as a 2-D array of size (N*N). Rotate the array by 90 degrees anti-clockwise. This code is written in C++ including library.

This is the easiest way to rotate the image. The idea is simple, first reverse the row using reverse() function

after that take the transpose of a reverse matrix.

 Input format:

    The first line contains a single integer N. Next, N lines contain N space-separated integers.

constraints:

    N<1000

Output format: 

    The output will be a rotated image by an angle of 90 degrees.

    for ex:  consider a 3*3 matrix

                  1 2 3                                          3 2 1                                     3 6 9 

                  4 5 6  after reversing row----->    6 5 4  after transpose------>   2 5 8

                  7 8 9                                          9 8 7                                      1 4 7

Download Complete Code

Comments

No comments yet