Coding | Mcqs | Multiple choice questions | Informative | Computer Science | Engineering | Aptitude | Quants | Verbal

INFEED

CTS & Wipro Automata Test 13 - 19th Sep

 

Rotate Matrix Anticlockwise

The program must accept an integer matrix of size NxN as the input. The program must rotate the given matrix by 90 degree in anticlockwise direction. Finally, the program must print modified matrix as the output.


Boundary Condition(s):

1 <= N <= 100

1 <= Matrix Element Value <= 9999999


Input Format:

The first line contains the value of N.

The next N lines contain N integers separated by space(s).


Output Format:

The first N lines contain N integers of the modified matrix separated by space(s).


Example Input/Output 1:

Input:

3

45 10 98

75 58 85

94 44 91


Output:

98 85 91

10 58 44

45 75 94


Example Input/Output 2:

Input:

6

91 92 59 10 40 87

73 31 44 64 24 57

12 67 61 93 25 46

53 28 37 11 98 35

84 51 99 41 54 89

96 43 18 23 33 16


Output:

87 57 46 35 89 16

40 24 25 98 54 33

10 64 93 11 41 23

59 44 61 37 99 18

92 31 67 28 51 43

91 73 12 53 84 96


Python:

n=int(input())

l=[];t=[]

for i in range(n):

    l.append(list(map(int,input().split())))

for i in l:

    t.append(i[::-1])

m=zip(*t)

for i in m:

    print(*i)


Product of Matrix and it's Transpose Program In Python


The program must accept two positive integers M and N as the input. The program must generate a 4×4 integer matrix by using the following conditions,
– The first element of the matrix must be the value of M.
– The successive elements are obtained by adding N to the current element.
Finally, the program must print the product of the generated matrix and it’s transpose.
Note:  For the matrix product, the elements in the same positions are multiplied to get the resultant matrix.

Boundary Condition(s):
1 <= M, N <= 100

Input Format:
The first line contains the values of M and N separated by a space.

Output Format:
The first four lines contain four integers in the product of the generated matrix and it’s transpose.

Example Input/Output 1:
Input:
4 1

Output:
16 40 72 112
40 81 130 187
72 130 196 270
112 187 270 361

Explanation:
The generated matrix as per the conditions mentioned above is
4 5 6 7
8 9 10 11
12 13 14 15
16 17 18 19
The transpose of the generated matrix is
4 8 12 16
5 9 13 17
6 10 14 18
7 11 15 19
The product of the generated matrix and it’s transpose is
16 40 72 112
40 81 130 187
72 130 196 270
112 187 270 361

Example Input/Output 2:
Input:
3 5

Output:
9 184 559 1134
184 784 1584 2584
559 1584 2809 4234
1134 2584 4234 6084


Python:


m,n=map(int,input().split())
k=m;p=[]
for i in range(4):
    l=[]
    for j in range(4):
        l.append(k);k+=n
    p.append(l)
a=p
r=[[0 for i in range(4)] for j in range(4)]
for i in range(4):
    for j in range(4):
        r[j][i]=a[i][j]
for i in range(4):
    for j in range(4):
        print(r[i][j]*p[i][j],end=' ')
    print()

2 Comments

  1. Thanks for Sharing This Article. Research Paper Writing Service is a website that allows you to Online Assignment Help online. Easily to write, Assignment Help Online with trained male and female teachers in Online Classes For Indian Students..

    ReplyDelete
  2. The global luxury car market size was valued at $495.7 billion in 2018 and is projected to reach $733.2 billion by 2026, registering a CAGR of 5.2% from 2019 to 2026. Asia-Pacific accounted for the highest share in 2018 and is expected to be the highest contributor to the global luxury car market, in terms of revenue, during the forecast period.

    ReplyDelete

Post a Comment

Previous Post Next Post