From 40986ceac862331450fbe7e8c0d28ce4ac240400 Mon Sep 17 00:00:00 2001 From: Tdsbeast <63647097+dipesh88@users.noreply.github.com> Date: Fri, 21 Oct 2022 23:05:16 +0530 Subject: [PATCH] Hacktoberfest2022 Hacktoberfest2022 --- kroneckerproduct.java | 63 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 kroneckerproduct.java diff --git a/kroneckerproduct.java b/kroneckerproduct.java new file mode 100644 index 0000000..0aecd1f --- /dev/null +++ b/kroneckerproduct.java @@ -0,0 +1,63 @@ +// Java code to find the Kronecker Product of +// two matrices and stores it as matrix C +import java.io.*; +import java.util.*; + +class GFG { + + // rowa and cola are no of rows and columns + // of matrix A + // rowb and colb are no of rows and columns + // of matrix B + static int cola = 2, rowa = 3, colb = 3, rowb = 2; + + // Function to computes the Kronecker Product + // of two matrices + static void Kroneckerproduct(int A[][], int B[][]) + { + + int[][] C= new int[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]; + System.out.print( C[i + l + 1][j + k + 1]+" "); + } + } + System.out.println(); + } + } + } + + // Driver program + public static void main (String[] args) + { + int A[][] = { { 1, 2 }, + { 3, 4 }, + { 1, 0 } }; + + int B[][] = { { 0, 5, 2 }, + { 6, 7, 3 } }; + + Kroneckerproduct(A, B); + } +} + +// This code is contributed by Gitanjali.