Sort by

recency

|

26 Discussions

|

  • + 0 comments

    include

    int main() { int A[3][3] = { {1, 2, 3}, {2, 3, 4}, {1, 1, 1} };

    int B[3][3] = {
        {4, 5, 6},
        {7, 8, 9},
        {4, 5, 7}
    };
    
    int C[3][3]; // Resultant matrix
    
    // Perform matrix addition: C = A + B
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            C[i][j] = A[i][j] + B[i][j];
        }
    }
    
    // Print the resulting matrix
    printf("Resultant matrix (C = A + B):\n");
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            printf("%d ", C[i][j]);
        }
        printf("\n");
    }
    
    return 0;
    

    }

  • + 0 comments

    Matrix Addition

    Add the two matrices given below and find the integers corresponding to , , , , , , , , and :

    [1 2 3] [4 5 6] [a b c] [2 3 4] + [7 8 9] = [d e f] [1 1 1] [4 5 7] [g h i] To submit your answer, enter the resultant values of each of the nine integers (i.e., , , , , , , , , and ) on a new line and click Submit Code.

    Input Format

    There is no input for this challenge; calculate the values of through using the matrices given above.

    Output Format

    In the text box below, enter the values of each of the nine integers on a new line. You must have a total of nine lines of output and the integers must be printed in order (i.e., , , , , , , , , and , respectively).

    Sample Output

    1 2 3 4 5 6 7 8 9

  • + 0 comments

    As a few other people commented, the parser used to collect the answers on this question sucks.

    # n_rows=3 #int(input()) # first get number of rows in maxtrix
    # n_mats=2 #int(input()) # then get number of matrices
    
    # m_names = ['mtrx_'+str(j) for j in range(0,n_mats)]
    
    # for i in range(0,n_mats):
    #     m=[]
    #     for r in range(0,n_rows):
    #         row = [int(x) for x in input().split()]
    #         m.append(row)
    #     m_names[i] = m
    
    # # add 2 nxn matrices:
    # def add_matrices(m1,m2):
    #     return[[m1[j][k]+m2[j][k] for k in range(len(m1))] for j in range(len(m1))]
    # my_matrix = add_matrices(m_names[0], m_names[1])
    
    # # print output
    # for j in range(len(my_matrix)):
    #     for k in range(len(my_matrix)):
    #         print(my_matrix[j][k])
    
    my_matrix = [[5,7,9],[9,11,13],[5,6,8]]
    # print output
    for j in range(len(my_matrix)):
        for k in range(len(my_matrix)):
            print(my_matrix[j][k])
    
  • + 0 comments
    int[][] m1 = { {1, 2, 3}, {2,3,4} , {1,1,1} }; 
            int[][] m2 = { {4,5,6}, {7,8,9},{4,5,7} }; 
            int[][] sum = new int[3][3];
            for(int i=0;i<3;i++){
               for(int j=0;j<3;j++){
               sum[i][j] = m1[i][j] + m2[i][j];
               System.out.println(sum[i][j]);
            }
            }
    
  • + 0 comments
    if __name__ == '__main__':
      a1, a2, a3 = [1, 2, 3], [2, 3, 4], [1, 1, 1]
      b1, b2, b3 = [4, 5, 6], [7, 8, 9], [4, 5, 7]
      c1, c2, c3 = [], [], []
      for i in range(len(a1)):
        c1.append(a1[i] + b1[i])
        c2.append(a2[i] + b2[i])
        c3.append(a3[i] + b3[i])
    
      print(*c1, sep='\n')
      print(*c2, sep='\n')
      print(*c3, sep='\n')