Search for question
Question

8. (8 pts) Solve below sub questions.

a)

Given a positive integer n, generate a square matrix filled with elements from 1 to n^2 in

a spiral order. Write a function generate_spiral_matrix(n) that returns the generated

spiral matrix. Here is example for it: (4 pts)/nb) You are given an nxn 2D matrix representing an image, where each pixel in the matrix

is represented by an integer. Your task is to rotate the image by 90 degrees (clockwise).

Write a function rotate_image(matrix) that rotates the image in-place. Here is the

example: (4 pts)

Fig: 1

Fig: 2