C Program for Kronecker Product of two matrices Last Updated : 23 Apr, 2022 Comments Improve Suggest changes Like Article Like Report Given a {m} imes{n} matrix A and a {p} imes{q} matrix B, their Kronecker product C = A tensor B, also called their matrix direct product, is an {(mp)} imes{(nq)} matrix. A tensor B = |a11B a12B| |a21B a22B| = |a11b11 a11b12 a12b11 a12b12| |a11b21 a11b22 a12b21 a12b22| |a11b31 a11b32 a12b31 a12b32| |a21b11 a21b12 a22b11 a22b12| |a21b21 a21b22 a22b21 a22b22| |a21b31 a21b32 a22b31 a22b32| Examples: 1. The matrix direct(kronecker) product of the 2×2 matrix A and the 2×2 matrix B is given by the 4×4 matrix : Input : A = 1 2 B = 0 5 3 4 6 7 Output : C = 0 5 0 10 6 7 12 14 0 15 0 20 18 21 24 28 2. The matrix direct(kronecker) product of the 2×3 matrix A and the 3×2 matrix B is given by the 6×6 matrix : Input : A = 1 2 B = 0 5 2 3 4 6 7 3 1 0 Output : C = 0 5 2 0 10 4 6 7 3 12 14 6 0 15 6 0 20 8 18 21 9 24 28 12 0 5 2 0 0 0 6 7 3 0 0 0 Recommended: Please solve it on PRACTICE first, before moving on to the solution. Below is the code to find the Kronecker Product of two matrices and stores it as matrix C : C // C code to find the Kronecker Product of two // matrices and stores it as matrix C #include <stdio.h> // rowa and cola are no of rows and columns // of matrix A // rowb and colb are no of rows and columns // of matrix B const int cola = 2, rowa = 3, colb = 3, rowb = 2; // Function to computes the Kronecker Product // of two matrices void Kroneckerproduct(int A[][cola], int B[][colb]) { int C[rowa * rowb][cola * colb]; // i loops till rowa for (int i = 0; i < rowa; i++) { // k loops till rowb for (int k = 0; k < rowb; k++) { // j loops till cola for (int j = 0; j < cola; j++) { // l loops till colb for (int l = 0; l < colb; l++) { // Each element of matrix A is // multiplied by whole Matrix B // resp and stored as Matrix C C[i + l + 1][j + k + 1] = A[i][j] * B[k][l]; printf("%d ", C[i + l + 1][j + k + 1]); } } printf(" "); } } } // Driver Code int main() { int A[3][2] = { { 1, 2 }, { 3, 4 }, { 1, 0 } }, B[2][3] = { { 0, 5, 2 }, { 6, 7, 3 } }; Kroneckerproduct(A, B); return 0; } Output : 0 5 2 0 10 4 6 7 3 12 14 6 0 15 6 0 20 8 18 21 9 24 28 12 0 5 2 0 0 0 6 7 3 0 0 0 Time Complexity: O(rowa*cola*rowb*colb), as we are using nested loops. Auxiliary Space: O(rowa*cola*rowb*colb), as we are using extra space in the matrix C. Please refer complete article on Kronecker Product of two matrices for more details! Comment More infoAdvertise with us Next Article C Program to Find Determinant of a Matrix K kartik Follow Improve Article Tags : C Language Similar Reads C Program for Matrix Chain Multiplication | DP-8 Write a C program for a given dimension of a sequence of matrices in an array arr[], where the dimension of the ith matrix is (arr[i-1] * arr[i]), the task is to find the most efficient way to multiply these matrices together such that the total number of element multiplications is minimum. Examples 7 min read C Program to Check Whether Two Matrices Are Equal or Not Here, we will see how to check whether two matrices are equal or not using a C Program Input: First Matrix: 1, 2, 3, 4 1, 2, 3, 4 1, 2, 3, 4 1, 2, 3, 4 Second matrix: 1, 2, 3, 4 1, 2, 3, 4 1, 2, 3, 4 1, 2, 3, 4 Output: Matrices are equal.Approach: For any two matrices to be equal, the number of rows 2 min read C Program to Find Determinant of a Matrix What is the Determinant of a Matrix? The determinant of a Matrix is a special number that is defined only for square matrices (matrices that have the same number of rows and columns). A determinant is used at many places in calculus and other matrices related to algebra, it actually represents the m 6 min read Matrix Multiplication in C A matrix is a collection of numbers organized in rows and columns, represented by a two-dimensional array in C. Matrices can either be square or rectangular. In this article, we will learn the multiplication of two matrices in the C programming language. ExampleInput: mat1[][] = {{1, 2}, {3, 4}} mat 3 min read Add Matrix in C Matrices are the collection of numbers arranged in order of rows and columns. In this article, we will learn to write a C program for the addition of two matrices.The idea is to use two nested loops to iterate over each element of the matrices. The addition operation is performed by adding the corre 4 min read Kronecker Product of two matrices Given an m*n matrix A and a p*q matrix B, their Kronecker product C = A tensor B, also called their matrix direct product, is a (m*p) * (n*q) matrix. A tensor B = |a11B a12B| |a21B a22B| = |a11b11 a11b12 a12b11 a12b12| |a11b21 a11b22 a12b21 a12b22| |a11b31 a11b32 a12b31 a12b32| |a21b11 a21b12 a22b11 10 min read Like