Crack Test


Count of Unique Integers based on Digit Sum

The program must accept an integer array of size N as the input. The program must print the count of integers after removing duplicate integers based on the digit sum of each integer as the output. That is if two integers have the same digit sum then it is a duplicate.
Boundary Condition(s):
2 <= N <= 100
1 <= Array Element Value <= 100000

Input Format:
The first line contains the value of N.
The second line contains N integers separated by space(s).
Output Format:
The first line contains the count of integers after removing duplicate integers based on the digit sum of each integer.
Example Input/Output 1:
Input:
6
93 73 84 86 38 55 
Output:
4

Explanation:
The digit sum of 93 is 12
The digit sum of 73 is 10
The digit sum of 84 is 12
The digit sum of 86 is 14
The digit sum of 38 is 11
The digit sum of 55 is 10
Here there are two duplicate integers 84 and 55. After removing these 2 integers in the array the count of integers in the array will become 4.
Hence the count 4 is printed as the output.

Example Input/Output 2:
Input:
8
4 15 13 42 112 24 76 94 
Output:
3
#include
#include
int main()
{
  int n;
  scanf("%d",&n);
  int a[n],b[n];
  int i,s,j,cnt=0,r=0,sum=0;
  for(i=0;i
  scanf("%d",&a[i]);
  
  for(i=0;i
      sum=0;
    s=a[i];
    while(s>0){
        r=s%10;
        sum+=r;
        s/=10;
    }
    b[i]=sum;
  }
  for(i=0;i
  printf("%d ",b[i]);
  printf("\n");
  for(i=0;i
      if(b[i]!=-1){
          for(j=i+1;j
              if(b[i]==b[j]){
                  b[j]=-1;
              }
          }
      }
  }
  for(i=0;i
      if(b[i]!=-1)
      cnt++;
  }
  printf("%d",cnt);
}                                                                                                            
Daily Test 22.10.18
Diagonally Dominant or Not

The program must accept an integer matrix of size NxN as the input. The program must Yes if the matrix is left diagonally dominant. Else the program must print No as the output. A diagonal is said to be dominant if elements in the diagonal are greater than or equal to the sum of all other elements in their row.
Note: Consider the absolute value for calculating the sum.
Boundary Condition(s):
3 <= N <= 50

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 line contains either 'Yes' or 'No'.

Example Input/Output 1:
Input:
3
3 -2 1
1 -3 -1
2 3 7
Output:
Yes

Explanation:
The diagonal element in the first row is 3.
|3| >= |-2| + |1| = |3| = |3|
The diagonal element in the second row is 3 (|-3| = 3).
|-3| >= |1| + |-1| = |-3| > |2|
The diagonal element in the third row is 7.
|7| >= |2| + |3| = |7| > |5|

Here, all the three left diagonal elements are greater than or equal to the sum of other two elements in their row. So, it is diagonally dominant.
Hence Yes is printed.

Example Input/Output 2:
Input:
4
4 -1 -1 -1
2 -6 2 3
1 2 4 1
2 3 1 -5
Output:

No
#include<stdio.h>
#include <stdlib.h>
int main()
{
    int i,j,n,cnt=0;
    scanf("%d",&n);
    int ar[n];
    for(i=0;i<n;i++)
    scanf("%d",&ar[i]);
    
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(ar[i]>ar[j])
            cnt++;
        }
    }
    printf("%d",cnt);
}                                                                                                                RunCode
Daily Test 20.10.18
 Count of Sorted Pairs
The program must accept an integer array of size N as the input. The program must print the count of pairs in the array so that the integers in the pair are sorted in descending order as the output. Boundary Condition(s): 1 <= N <= 100 Input Format: The first line contains the value of N. The second line contains N integers separated by space(s). Output Format: The first line contains the count of pairs in the array based on the condition mentioned above. Example Input/Output 1: Input: 5 2 8 7 5 6 Output: 5 Explanation: The pairs which satisfy the given conditions are (8, 7), (8, 5), (8, 6), (7, 5) and (7, 6). The count of pairs is 5. Hence the output is 5 Example Input/Output 2: Input: 7 51 56 5 25 75 38 73 Output: 8Code in C --> RunCode
#include<stdio.h>
#include <stdlib.h>

int main()
{
    int i,j,n,cnt=0;
    scanf("%d",&n);
    int ar[n];
    for(i=0;i<n;i++)
    scanf("%d",&ar[i]);
    
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(ar[i]>ar[j])
            cnt++;
        }
    }
    printf("%d",cnt);

}                                                                                                                 RunCode
Daily Test 15.10.18
X Lines Integers Pattern
The program must accept two integers N and X as the input. The program must print the desired pattern as shown in the Example Input/Output sections.
Boundary Condition(s):
1 <= N <= 100
1 <= X <= 10
Example Input/Output 1:
Input:
8 5
Output:
8 
16 17 
24 25 26 27 
32 33 34 35 36 37 38 39 
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 

Example Input/Output 2:
Input:
9 3
Output:
9 
18 19 
27 28 29 30 
36 37 38 39 40 41 42 43  
Code in C --> Run Code
#include<stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    int n,x;
    scanf("%d %d",&n,&x);
    for(int i=0;i<x;i++)
    {
        int t=n*(i+1);
        for(int j=0;j<pow(2,i);j++)
        {
            printf("%d ",t++);
        }
        printf("\n");
    }
}
Daily Test 12.10.18
Horizontal and Vertical Zig - Zag
The program must accept an integer N as the input. The program must print the desired pattern as shown in the Example Input/Output section.
Boundary Condition(s):
1 <= N <= 100
Input Format:
The first line contains the value of N.
Output Format:
The first N lines contain the desired pattern as shown in the Example Input/Output section.
Example Input/Output 1:
Input:
5
Output:
1 2 3 4 5
2 9 8 7 6
3 8 10 11 12
4 7 11 14 13
5 6 12 13 15

Example Input/Output 2:
Input:
8
Output:
1 2 3 4 5 6 7 8
2 15 14 13 12 11 10 9
3 14 16 17 18 19 20 21
4 13 17 26 25 24 23 22
5 12 18 25 27 28 29 30
6 11 19 24 28 33 32 31
7 10 20 23 29 32 34 35
8 9 21 22 30 31 35 36Code in C -->                                                                                   Run Code 
#include<stdio.h>
#include <stdlib.h>

int main()
{
  int n,a=1;
  scanf("%d",&n);
  int i,j,k=1;
  int arr[n][n];
  for(i=0;i<n;i++)
  {
      if(i%2==0)
      {
          for(j=0;j<n;j++)
          {
              if(i<=j)
              {
                  arr[j][i]=a;
                  a+=1;
              }
          }
      }
      else
      {
          for(j=n-1;j>0;j--)
          {
              if(i<=j)
              {
                  arr[j][i]=a;
                  a++;
              }
          }
      }
  }
  int ar[n][n];
  for(i=0;i<n;i++)
    {
        for(j=0;j<i;j++)
        {
            printf("%d ",arr[i][j]);
        }
         ar[i][i]=arr[i][i];
         for(int p=0;p<i;p++)
         printf("");
        for(j=0;j<n-i;j++)
        {
            if(i%2==0)
            printf("%d ",ar[i][i]++);
            else
            printf("%d ",ar[i][i]--);
        }
        printf("\n");
    }
  return 0;
}                                                                                                                  Run Code
Daily Test 12.10.18
Two String Reverse Interlace Pattern
Two string values of equal length are passed as the input to the program. The program must print the desired pattern as shown in the Example Input/Output sections.
Boundary Condition(s):
1 <= Length of each string <= 1000

Example Input/Output 1:
Input:
min max
Output:
mxianm

Example Input/Output 2:
Input:
good real
Output:
gloaoedrCode in C -->                                                                                         Run Code
#include<stdio.h>
#include <stdlib.h>
#include<string.h>
int main()
{
  char s1[1000],s2[1000];
  scanf("%s %s",s1,s2);
  int l=strlen(s1);
  for(int i=0;i<2*l;i++)
  {
        printf("%c",s1[i]);
        printf("%c",s2[l-1-i]);
  }
 }                                                                                                                  Run Code
1. Find n-th term of series 1, 3, 6, 10, 15, 21…
Given a number N, find the Nth term in the series 1, 3, 6, 10, 15, 21…
Input : The first line of input contains a positive integer T denoting the number of testcases. For each test case, there will be a single line containing an integer N.
Output: 
For each testcase, print the Nth term.
Constraints: 1 <= T <= 100 1 <= N <= 1000
Examples: Input: 
2
3 4
Output: 6 10