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

INFEED

SBT | DAILY TEST | 14 JUNE RETEST | TECHNICAL MCQ | CODING

 TECHNICAL MCQ 

person writing on white paper

1.

#include<stdio.h>
int main()
{
int value[4] = {7, 4, 9, 15};
int x=4, y;
while(x)
{
y=value[x]+x;
x--;
}
printf("%d",y);
}


output : 5


2.

#include<stdio.h>
int main()
{
int arr[2][2][2] = { {10,20,30,40}, {55,66,77,88} };
int *x,*y;
x=&arr[2][2][2];
*y=***arr;
printf("%d----%d",*x,*y);
}


output : run time error


3.

#include<stdio.h>
int main()
{
int array[5],x=0;
while(x<5)
array[x]=++x;
for(x=0;x<5;x++)
printf("%d ",array[x]);
}

 

output : garbage value,1,2,3,4

 

4.

Choose the Correct answers
int arr [9] = {9, 9, 9};
1. arr[8] is the last element of the array arr
2. The value of arr[7] is 9
3. The value of arr[3] is 9
4. The value of arr[2] is 9

 

output : 1 and 4

 

5.

If array is initialized where it is declared, then mentioning __ of array is optional.

output : Dimension

 

6.

How many maximun number of dimensions an array can have in C?

output : none of the above

 

7. equivalent to 

int fun(int arr[])

output : int fun(int arr[2])


8. Store the information above an array which is used in a program

output : Dope Vector


9.

What will be the output of the program if the array begins at address 94044?
#include<stdio.h>
int main()
{
int x_arr[] = {22, 33, 44, 55, 66};
printf("%u, %u \n ", x_arr, &x_arr);
return 0;

}

output : 94044 94044


10.

#include<stdio.h>
int main()
{
int arr[5]={100,19,43,74,32};
int x;
x=(arr+1)[3];
printf("%d",x);
}

output : 32

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

Problem 1:

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


C++ CODE:

 #include <iostream>

#include <iomanip>

using namespace std;

 

#define M 5

#define N 5

 

// Shift all matrix elements by 1 in spiral order

void shiftMatrix(int mat[M][N])

{

   

}

 

int main()

{

    int n;

    cin>>n;

    int mat[n][n];

    for(int i=0;i<n;i++)

    {

        for(int j=0;j<n;j++)

            cin>>mat[i][j];

    }

 

    int top = 0, bottom = n - 1;

    int left = 0, right = n - 1;

    int prev = mat[0][0];

 

    while (1)

    {

        if (left > right) {

            break;

        }

 

        // change top row

        for (int i = left; i <= right; i++) {

            swap(mat[top][i], prev);

        }

 

        top++;

 

        if (top > bottom) {

            break;

        }

 

        // change right column

        for (int i = top; i <= bottom; i++) {

            swap(mat[i][right], prev);

        }

 

        right--;

 

        if (left > right) {

            break;

        }

 

        // change bottom row

        for (int i = right; i >= left; i--) {

            swap(mat[bottom][i], prev);

        }

 

        bottom--;

 

        if (top > bottom) {

            break;

        }

 

        // change left column

        for (int i = bottom; i >= top; i--) {

            swap(mat[i][left], prev);

        }

 

        left++;

    }

 

    // the first element of the matrix will be the last element replaced

    mat[0][0] = prev;

   

   

   

 

    for (int i = 0; i < n; i++)

    {

        for (int j = 0; j < n; j++) {

            cout << mat[i][j]<<" ";

        }

        cout << endl;

    }

 

    return 0;

}


Problem 2:

Problem Statement
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++ CODE:


#include<bits/stdc++.h>

using namespace std;

#define N 105



 // } Driver Code Ends



/*  Function to rotate matrix by 90 degrees

*   n: input for matrix size

*   N: size defined globally

*/

void rotateby90(int n, int a[][N]){

    

    // Your code here

    for(int i=0;i<n;i++)

    {

        for(int j=i;j<n;j++)

            swap(a[i][j],a[j][i]);

    }

    

    for(int i=0;i<n/2;i++)

    {

        for(int j=0;j<n;j++)

        {

            int temp=a[i][j];

            a[i][j]=a[n-1-i][j];

            a[n-1-i][j]=temp;

        }

    }

    

}


// { Driver Code Starts.


int main()

{

    // int t;

    // cin>>t; //inputting testcases

    // while(t--)

    // {

        int n;

        cin>>n; //inputing n for square matrix

        int a[N][N],i,j;

        for(i=0;i<n;i++)

        {

            for(j=0;j<n;j++)

            {

                cin>>a[i][j]; //Inputting the matrix

            }

        }

        

        rotateby90(n, a);

        

        for(i=0;i<n;i++)

        {

            for(j=0;j<n;j++)

            {

                cout<<a[i][j]<<" "; //printing the resultant matrix

            }

            cout<<"\n";

        }

        cout<<endl;

        

    // }

    return 0;

}  // } 


Problem 3:

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 CODE:

sum1,sum2=0,0

sum11=[]

sum22=[]

n=int(input())

m=[]

for i in range(n):

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

    m.append(l)

    

   

for i in range(n):

    for j in range(n):

        if i+j==n-1:

                sum11.append(m[i][j])

                sum1+=m[i][j]

        if i==j:

                sum22.append(m[i][j])

                sum2+=m[i][j]

print(sum1*sum2)

 

 


Post a Comment

Previous Post Next Post