Write a program to rotate a matrix of integer values given the number of rota- tions. For example, if the input matrix is 1 2] and the number of rotations is 2, the output will be [4 3] 1 If the number of rotations is negative, the rotation will be anti-clockwise. Note: You should NOT use any additional arrays. You should define a function rotate and pass needed arguments to do the task and then return the result. Your program should work for 2*2, 3*3 and 4*4 matrices. You can either solve the problem for N*N case or overload 3 functions with the same name for differ- ent sizes (one for 2*2 matrices, one for 3*3 matrices and one for 4*4 matrices).

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 23PE
icon
Related questions
Question

using Arrays and Vectors/ User-defined Functions/ in C++

without using the swap; 

Write a program to rotate a matrix of integer values given the number of rota-
tions. For example, if the input matrix is
[1 2
3 4
and the number of rotations is 2, the output will be
[4 3
|2 1
If the number of rotations is negative, the rotation will be anti-clockwise.
Note: You should NOT use any additional arrays. You should define a function
rotate and pass needed arguments to do the task and then return the result.
Your program should work for 2*2, 3*3 and 4*4 matrices. You can either solve
the problem for N*N case or overload 3 functions with the same name for differ-
ent sizes (one for 2*2 matrices, one for 3*3 matrices and one for 4*4 matrices).
Transcribed Image Text:Write a program to rotate a matrix of integer values given the number of rota- tions. For example, if the input matrix is [1 2 3 4 and the number of rotations is 2, the output will be [4 3 |2 1 If the number of rotations is negative, the rotation will be anti-clockwise. Note: You should NOT use any additional arrays. You should define a function rotate and pass needed arguments to do the task and then return the result. Your program should work for 2*2, 3*3 and 4*4 matrices. You can either solve the problem for N*N case or overload 3 functions with the same name for differ- ent sizes (one for 2*2 matrices, one for 3*3 matrices and one for 4*4 matrices).
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Algebraic Expression
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning