• Study Materials – Company wise
    • Infosys Archive
    • Accenture Archive
    • AMCAT Archive
    • Capgemini Archive
    • Cisco Archive
    • CoCubes Archive
    • Cognizant(CTS) Archive
    • Dell Archive
    • Deloitte Archive
    • DXC Archive
    • Goldman Sachs Archive
    • Hexaware Technologies Archive
    • LTI Archive
    • MindTree Archive
    • TCS Archive
    • Virtusa Archive
    • Wipro Archive
  • Interview Preparation – E Books
    • C Interview Questions
    • Data Structures Interview Questions
    • DBMS Interview Questions
    • HR Interview Questions
    • Java Interview Questions
    • Operating System Interview Questions
    • Python Interview Questions
    • SQL Query Interview Questions
  • Programming
    • C Programming MCQs
    • C Code Snippets – Output Questions
    • Python Code Snippets – Output Questions
  • Aptitude
    • Verbal Ability for Placements
    • Quant for Placements
  • Register
  • Login
CODE OF GEEKS

We at CODE OF GEEKS, aim at providing best and quality content for our users at no extra cost.

    • Study Materials – Company wise
      • Infosys Archive
      • Accenture Archive
      • AMCAT Archive
      • Capgemini Archive
      • Cisco Archive
      • CoCubes Archive
      • Cognizant(CTS) Archive
      • Dell Archive
      • Deloitte Archive
      • DXC Archive
      • Goldman Sachs Archive
      • Hexaware Technologies Archive
      • LTI Archive
      • MindTree Archive
      • TCS Archive
      • Virtusa Archive
      • Wipro Archive
    • Interview Preparation – E Books
      • C Interview Questions
      • Data Structures Interview Questions
      • DBMS Interview Questions
      • HR Interview Questions
      • Java Interview Questions
      • Operating System Interview Questions
      • Python Interview Questions
      • SQL Query Interview Questions
    • Programming
      • C Programming MCQs
      • C Code Snippets – Output Questions
      • Python Code Snippets – Output Questions
    • Aptitude
      • Verbal Ability for Placements
      • Quant for Placements
    • Register
    • Login
  • [email protected]
  • ..
Login / Register
Apply Now
CODE OF GEEKS
CODE OF GEEKS
  • Study Materials – Company wise
    • Infosys Archive
    • Accenture Archive
    • AMCAT Archive
    • Capgemini Archive
    • Cisco Archive
    • CoCubes Archive
    • Cognizant(CTS) Archive
    • Dell Archive
    • Deloitte Archive
    • DXC Archive
    • Goldman Sachs Archive
    • Hexaware Technologies Archive
    • LTI Archive
    • MindTree Archive
    • TCS Archive
    • Virtusa Archive
    • Wipro Archive
  • Interview Preparation – E Books
    • C Interview Questions
    • Data Structures Interview Questions
    • DBMS Interview Questions
    • HR Interview Questions
    • Java Interview Questions
    • Operating System Interview Questions
    • Python Interview Questions
    • SQL Query Interview Questions
  • Programming
    • C Programming MCQs
    • C Code Snippets – Output Questions
    • Python Code Snippets – Output Questions
  • Aptitude
    • Verbal Ability for Placements
    • Quant for Placements
  • Register
  • Login
0

Cart

Matrix Sum

  • January 29, 2020
  • CODE OF GEEKS
  • 7

Given a row/column count and a matrix, your job is to find those possible 2*2 matrix where each should follow the given rule :

-> Each element of matrix should be divisible by sum of its digits.

Input : 

First Input : Row count, Column Count

Second Input : Matrix

Output : 

2*2 matrices satisfying the rule.

Sample Testcases :


I/P 1:

4 3

40 42 2

30 24 27

180 190 40

11 121 13

O/P 1:

40 42

30 24

30 24

180 190

24 27

190 40

 

Tags: infosys last year handson problemsinfytqinfytq examinfytq handson problems of last yearinfytq handson questionsinfytq last year problemsinfytq last year questionsLast year questions Infytqmatrix problem for infytqmatrix problem infytqprepare infytq question
  • Previous Great Sum
  • Next Area of Circle using C

7 comments on “Matrix Sum”

  1. RISHABH GUPTA says:
    June 2, 2020 at 10:51 am

    #My solution in Python
    #NOTE:- IN GIVEN EXAMPLE THERE IS AN ERROR EITHER IN OUTPUT(AS OUTPUT ALSO INCLUDE 42 2 24 27) OR INPUT(IN PLACE OF 2 THERE IS SOMETHING ELSE)
    #CORRECT ME IF I AM WRONG

    row,col=map(int,input().split())
    matrix=[]
    for _ in range(row):
    matrix.append(input().split())
    for i in range(row-1):
    for j in range(col-1):
    a= matrix[i][j]
    b= matrix[i][j+1]
    c= matrix[i+1][j]
    d= matrix[i+1][j+1]

    if int(a)%sum(map(int,list(a)))==0 and int(b)%sum(map(int,list(b)))==0 and int(c)%sum(map(int,list(c)))==0 and int(d)%sum(map(int,list(d)))==0:
    print(a, b,)
    print(c, d)

    Reply
  2. king says:
    August 19, 2020 at 11:09 am

    is this code is executed

    Reply
  3. AR says:
    August 19, 2020 at 12:39 pm

    rows, cols = map(int, input().split())
    mat = []
    for i in range(rows):
    mat.append(list(map(int, input().split())))

    for i in range(rows-1):
    for j in range(cols-1):
    a = mat[i][j]
    b = mat[i][j+1]
    c = mat[i+1][j]
    d = mat[i+1][j+1]
    all_occ = [a, b, c, d]
    if len(list(filter(lambda item: item % sum(map(int, list(str(item)))) == 0, all_occ))) == 4:
    print(a, b)
    print(c, d)

    Reply
  4. ganesh says:
    February 20, 2021 at 4:05 am

    row, col = map(int, input().split())

    arr = []
    for i in range(0, row):
    arr.append(list(map(int, input().split())))

    for i in range(0, row-1):
    for j in range(0, col-1):
    count = 0
    for k in range(i,i+2):
    for l in range(j,j+2):
    sdl = sum([int(z) for z in str(arr[k][l])])
    #print(sdl)
    if arr[k][l] % sdl == 0:
    count += 1
    if count == 4:
    print(arr[i][j],arr[i][j+1])
    print(arr[i+1][j],arr[i+1][j+1])

    Reply
  5. boddam sathvika says:
    April 15, 2021 at 5:33 pm

    def is_divisible(n):
    s = sum(list(map(int,str(n))))
    if n%s==0:
    return True
    else:
    return False

    row, col = map(int, input().split())
    matrix = []
    for i in range(row):
    matrix.append(list(map(int,input().split())))
    col=len(matrix[0])
    for r in range(row-1):#3
    for c in range(col-1):#2
    if(is_divisible(matrix[r][c]) and is_divisible(matrix[r][c+1]) and is_divisible(matrix[r+1][c]) and is_divisible(matrix[r+1][c+1])):
    print(matrix[r][c],matrix[r][c+1])
    print(matrix[r+1][c],matrix[r+1][c+1])

    Reply
  6. Anmol Shah Anmol Shah says:
    April 16, 2021 at 5:25 pm

    r,c = list(map(int,input().split()))

    def condition(num):
    sum = 0
    a = num
    while num:
    sum = sum + num%10
    num = num // 10
    return a%sum == 0

    mat = []
    output = []
    for _ in range(r):
    mat.append(list(map(int, input().split())))
    for i in range(r-1):
    for j in range(c-1):
    if condition(mat[i][j]) and condition(mat[i][j+1]) and condition(mat[i+1][j]) and condition(mat[i+1][j+1]):
    output.append([ mat[i][j], mat[i][j+1] ])
    output.append([ mat[i+1][j], mat[i+1][j+1] ])

    print(output)

    Reply
  7. Ashutosh Tripathi Ashutosh Tripathi says:
    April 17, 2021 at 6:43 am

    import java.io.*;
    import java.util.*;
    import java.util.Collections;

    public class Matrix {

    public static boolean checkSum(int a,int b,int c,int d){
    int count=0;
    int[] tt={a,b,c,d};
    try{
    for(int x:tt){
    int ele=x;
    int sum=0;
    while(x>0){
    sum=sum+(x%10);
    x=x/10;
    }
    if(ele%sum==0)
    count++;

    }

    }catch(ArithmeticException e){
    // e.printStackTrace();
    return false;
    }
    if(count==4) return true;
    else return false;
    }

    public static void main(String args[]) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    String str[] = br.readLine().split(” “);
    int r = Integer.parseInt(str[0]);
    int c = Integer.parseInt(str[1]);
    int mat[][] = new int[r][c];
    // int two[][] = new int[r][c];

    for(int i = 0; i < r; i++) {
    String in[] = br.readLine().split(" ");
    for(int j = 0; j < c; j++) {
    mat[i][j] = Integer.parseInt(in[j]);}}

    ArrayList al = new ArrayList();

    for(int i = 0; i < mat.length-1; i++) {
    for(int j = 0; j 0){
    System.out.print(al.get(0)+” “);
    al.remove(0);
    }
    System.out.println(“———–“);
    }

    }}

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

CODE OF GEEKS

Subscribe to Newsletter

CODE OF GEEKS

Learn | Code | Achieve

Reach us

[email protected]
We at CODE OF GEEKS, aim at providing quality content to our users at no cost.
CODE OF GEEKS

Important Pages

About us
Advertise
Privacy Policy
Terms and Conditions

Placements – Study Materials

TCS NQT     Wipro     CapGemini
Accenture     MindTree     CTS
DXC     Hexaware Technologies     AMCAT
CoCubes     Goldman Sachs     Dell
Cisco     Deloitte     Virtusa     LTI     Infosys   

Courses

  • Mail Us
  • Login/Register

Recent Posts

TCS Reasoning 2021
  • October 4, 2021
TCS Verbal 2021
  • October 4, 2021

Copyright 2021 CODE OF GEEKS. All Rights Reserved.

  • →