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

INFEED

Daily Assessment-4 T--E--R--V

 

Unity is Strength

Infinity Stones are so powerful, and no normal human being can hold the stone and stay alive. After the avengers has set the path right by destroying Thanos. Thanos had sent a time remnant. Time remnants, also known as timeline remnants or temporal duplicates. He sent back in time and destroyed Tony Start, the Iron Man. So without him, who will snap the finger and kill Thanos?

But time are so many possibilities. Now normal people have joined hands to fight against Thanos. But no one can hold the stone alone. So Dr. Banner has designed a machine such that, the machine can be held by many people together. The people are categorized by their power, from 1 to N. They have to stand in form of a square. Dr. Banner has found out that people with powers of 1 to N are required, and a person with power 1 will be standing in the center and people with power 2 will form a smallest possible square around him. This will be continued until people with power N form a square. Now they all will will hold the device together and destroy Thanos. Dr. Banner, is busy making the machine ready. Can you help him, by making people stand in  the required order and protect the world!

Input Format : One single integer N

Input Constraints : 1<=N<=100

Output Format : The pattern thus required

Sample Input :

4

Sample Output :

4 4 4 4 4 4 4 
4 3 3 3 3 3 4 
4 3 2 2 2 3 4 
4 3 2 1 2 3 4 
4 3 2 2 2 3 4 
4 3 3 3 3 3 4 
4 4 4 4 4 4 4 

C-Code:

#include <stdio.h> 
int min(int a,int b,int c,int d)
{
    int e=(a<b)?a:b;
    int f=(c<d)?c:d;
    return (e<f)?e:f;
}
int main()
{int n,i,j,x;
scanf("%d",&n);
for(i=0;i<(2*n-1);i++,printf("\n"))
{
    for(j=0;j<(2*n-1);j++)
    {
        x=min(i,j,((2*n-2)-i),((2*n-2)-j));
        printf("%d ",n-x);
    }
}
  return 0;
}


C-Sort

Given a 2D array , sort each column in ascending order.

Input Format : The first line consists of an integer N, which denotes the row and column size Next N lines follow the matrix

Input Constraints : 1 <= N <= 500 1 <= Mat[i][j] <= 10^9

Output Format : N lines of matrix output

Sample Input :

3
1 3 2
8 7 9
5 4 6

Sample Output :

1 3 2
5 4 6
8 7 9

C-Code

#include <stdio.h>
int main()
{
    int i, j, k, m, n;
    scanf("%d",&n);
  unsigned long long int array2[n][n],a;
    m=n;
    for (i = 0; i < m; ++i)
    {
        for (j = 0; j < n; ++j)
        {
            scanf("%lld", &array2[i][j]);
        }
    }
    for (j = 0; j < n; ++j)
    {
        for (i = 0; i < m; ++i)
        {
            for (k = i + 1; k < m; ++k)
            {
                if (array2[i][j] > array2[k][j])
                {
                    a = array2[i][j];
                    array2[i][j] = array2[k][j];
                    array2[k][j] = a;
                }
            }
        }
    }
    for (i = 0; i < m; ++i)
    {
        for (j = 0; j < n; ++j)
        {
            printf("%lld ", array2[i][j]);
        }
        printf("\n");
    }
  return 0;
}


Post a Comment

Previous Post Next Post