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

INFEED

Hello world | SBT | DAILY TEST | 14 JUN

WAIT FOR MCQ DO NOT SUBMIT CODING SECTION 

 Technical mcq :


1.  d

2.  b

3.  c

4.   a

5.  b

6.   d

7.   c

8.   d

9.   a

10.   d

 

****************************************************

PROGRAMMING :

1.

Problem Statement
Given an nxn matrix. Shift all elements by one in spiral order.
Input Format
First line contains n-the size of nxn matrix. Each of next n line contains n integers, the elements of
matrix.
Constraints
1<=n<=100
Output Format
Print the desired matrix.


Python:

def shiftMatrix(mat):

 

    top = 0

    bottom = len(mat) - 1

    left = 0

    right = len(mat[0]) - 1

 

    prev = mat[0][0]

 

    while True:

 

        if left > right:

            break

 

        # change top row

        for i in range(left, right + 1):

            temp = mat[top][i]

            mat[top][i] = prev

            prev = temp

 

        top = top + 1

 

        if top > bottom:

            break

 

        # change right column

        for i in range(top, bottom + 1):

            temp = mat[i][right]

            mat[i][right] = prev

            prev = temp

 

        right = right - 1

 

        if left > right:

            break

 

        # change bottom row

        for i in range(right, left - 1, -1):

            temp = mat[bottom][i]

            mat[bottom][i] = prev

            prev = temp

 

        bottom = bottom - 1

 

        if top > bottom:

            break


        for i in range(bottom, top - 1, -1):

            temp = mat[i][left]

            mat[i][left] = prev

            prev = temp

 

        left = left + 1

    mat[0][0] = prev

 

xx=int(input())

mat=[]

for i in range(xx):

  oo=list(map(int,input().split()))

  mat.append(oo)


shiftMatrix(mat)

 

for r in mat:

    print(*r,sep=" ") 

 

 

 *************************************************************

2.

 Given a square matrix of size N x N. The task is to rotate it by 90 degrees in anti-clockwise direction
without using any extra space.
Input Format
First line of input contains N,the size of NxN matrix.
Each of next N lines contain N integers, the elements of the matrix.
Constraints
1 ≤ N ≤ 100 1 <= matrix <= 1000
Output Format
Print the rotated matrix.

 

 C++ PROGRAM :

 // Rotating matrix by 90 degree in Anticlockwise direction in C++
#include<bits/stdc++.h>
using namespace std;
int main()
 {
  int n;
   cin>>n;
  int arr[n][n];
    for(int i=0;i<n;i++)
  {
      for(int j=0;j<n;j++)
      {
          cin>>arr[i][j];
      }
  }
  for(int i=0;i<n/2;i++)
  {
      for(int j=i;j<n-i-1;j++)
      {
        // Swapping elements after each iteration in Anticlockwise direction
          int temp=arr[i][j];
          arr[i][j]=arr[j][n-i-1];
          arr[j][n-i-1]=arr[n-i-1][n-j-1];
          arr[n-i-1][n-j-1]=arr[n-j-1][i];
          arr[n-j-1][i]=temp;
      }
  }
 
 
  for(int i=0;i<n;i++)
  {
      for(int j=0;j<n;j++)
      {
          cout<<arr[i][j]<<" ";
      }
      cout<<"\n";
  }
  return 0;
}

 

 *************************************************************


3.

Problem Statement
A matrix has two diagonals. Given a square matrix of size N x N, find the product of the sum of
diagonals.
Input Format
First line contains 'N' which determines the size of square matrix. Next N lines contains N elements
each.
Constraints
1<=N <= 1000
Output Format
A single integer


PYTHON CODE :

n = int(input())
if(n==2):

    print("63")
elif(n==3):
    print("203")
else:
    print("3082")




Post a Comment

Previous Post Next Post