Computer Science, asked by 19951A05D, 5 months ago

Given a matrix mat[][] of size M*N. Traverse and print the matrix in spiral form.

Constraints:
1 <= T <= 100
2 <= M,N <= 10
0 <= Ai <= 100

Input:

The first line of the input contains a single integer T, denoting the number of test cases. Then T test cases follow. Each testcase has 2 lines. First line contains M and N respectively separated by a space. Second line contains M*N values separated by spaces.

Output:

Elements when travelled in Spiral form, will be displayed in a single line and print P before a prime element. if no prime found print NULL PRIME MATRIX

Sample Input 1:
2
4 4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
2 3
10 20 30 40 50 60

Sample Output 1:
1 P2 P3 4 8 12 16 15 14 P13 9 P5 6 P7 P11 10
NULL PRIME MATRIX

Explanation:
Testcase1 : input: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
It prints P before every prime number.
1 P2 P3 4 8 12 16 15 14 P13 9 P5 6 P7 P11 10

Testcase2 :
10 20 30 40 50 60
No prime numbers exist.
NULL PRIME MATRIX

Answers

Answered by TANI8H
1

The matrix whose every element is zero is called a null or zero matrix and it is denoted by 0. Thus for A and 0 of the same order we have A + 0 = A. For example, [00] is a zero matrix of order 1 × 2. [00] is a zero or null matrix of order 2 × 1.

HOPE IT WILL HELP YOU :)

Similar questions