Given two square Matrices A[][] and B[][]. Your task is to complete the function multiply which stores the multiplied matrices in a new matrix C[][].
 
Example 1:
Input: 
N = 2
A[][] = {{7, 8}, {2 , 9}}
B[][] = {{14, 5}, {5, 18}}
Output: 
C[][] = {{138, 179}, {73, 172}}
 
Example 2:
Input: 
N = 2
A[][] = {{17, 4}, {17 , 16}}
B[][] = {{9, 2}, {7, 1}}
Output: 
C[][] = {{181, 38}, {265, 50}}
Constraints:
1 <=T<= 100
1 <= N <= 20

Source: geeksforgeeks | Difficulty: EASY
Tags: Matrices

Data structures

Starter code: # Your task is to complete this function

# function should store the multiplication in C

def multiply(A, B, C, n):

    # Code here

Solutions:
def multiply(A, B, C, n):
	for i in range(n):
		for j in range(n):
			for k in range(n):
				C[i][j] += A[i][k] * B[k][j]


def multiply(A, B, C, n):
	p = list()
	sum = list()
	for i in range(n):
		for j in range(n):
			for k in range(n):
				C[i][j] += A[i][k] * B[k][j]


def multiply(A, B, C, n):
	for i in range(len(A)):
		for j in range(len(A[0])):
			for k in range(len(B)):
				C[i][j] += A[i][k] * B[k][j]
	return C[i][j]


import numpy as np

def multiply(A, B, C, n):
	for i in range(len(A)):
		for j in range(len(B[0])):
			for k in range(len(B)):
				C[i][j] += A[i][k] * B[k][j]


def multiply(A, B, C, n):
	(row, col) = ([], [])
	for i in range(n):
		for j in range(n):
			(row, col) = (A[i], [col[j] for col in B])
			total = 0
			for k in range(n):
				C[i][j] += row[k] * col[k]


def multiply(A, B, C, n):
	d = [[0 for i in range(n)] for j in range(n)]
	for i in range(n):
		for j in range(n):
			d[i][j] = B[j][i]
	ans = 0
	for k in range(n):
		for i in range(n):
			for j in range(n):
				ans += A[k][j] * d[i][j]
			C[k][i] = ans
			ans = 0
	return C


def multiply(A, B, C, n):
	k = 0
	l = 0
	for i in range(n):
		sum = 0
		for j in range(n):
			sum += A[i][j] * B[j][i]
			for k in range(n):
				C[i][j] += A[i][k] * B[k][j]


import numpy as np

def multiply(A, B, C, n):
	for i in range(n):
		for j in range(n):
			for k in range(n):
				C[i][j] += A[i][k] * B[k][j]
	return C


def multiply(A, B, C, n):
	row_a = len(A)
	row_b = len(B)
	column_a = len(A[0])
	column_b = len(B[0])
	for i in range(row_a):
		for j in range(column_b):
			for k in range(row_b):
				C[i][j] += A[i][k] * B[k][j]
	return C


def multiply(A, B, C, n):
	for a in range(len(A)):
		for b in range(len(B)):
			for c in range(len(B[b])):
				C[a][b] += A[a][c] * B[c][b]
	return C


def multiply(A, B, C, n):
	for x in range(n):
		for y in range(n):
			m = 0
			for a in range(n):
				m += A[x][a] * B[a][y]
			C[x][y] = m


from numpy import *

def multiply(A, B, C, n):
	for i in range(len(A)):
		for j in range(len(B[0])):
			for k in range(len(B)):
				C[i][j] += A[i][k] * B[k][j]


from numpy import array

def multiply(A, B, C, n):
	lst1 = array(A)
	lst2 = array(B)
	ans = lst1 @ lst2
	for i in range(n):
		for j in range(n):
			C[i][j] = ans[i][j]
	return C


def multiply(A, B, C, n):
	output = [[sum((a * b for (a, b) in zip(A_row, B_col))) for B_col in zip(*B)] for A_row in A]
	for i in range(n):
		for j in range(n):
			C[i][j] = output[i][j]


def multiply(matrixA, matrixB, C, n):
	n = len(matrixA[0])
	ans = []
	for i in range(n):
		l = []
		for j in range(n):
			su = 0
			for k in range(n):
				mu = matrixA[i][k] * matrixB[k][j]
				su += mu
			l.append(su)
		ans.append(l)
	for i in range(n):
		for j in range(n):
			C[i][j] = ans[i][j]