In: Computer Science
Need to write a code using c# Strassen’s Algorithm for matrix multiplication.
CODE
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace StrassenMultiplication { class Exercise { static void Main(string[] args) { int i, j,m,n; Console.WriteLine("Enter the Number of Rows and Columns : "); m = Convert.ToInt32(Console.ReadLine()); n = Convert.ToInt32(Console.ReadLine()); int[,] a = new int[m, n]; Console.WriteLine("Enter the First Matrix"); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { a[i, j] = int.Parse(Console.ReadLine()); } } Console.WriteLine("First matrix is:"); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { Console.Write(a[i, j] + "\t"); } Console.WriteLine(); } int[,] b = new int[m, n]; Console.WriteLine("Enter the Second Matrix"); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { b[i, j] = int.Parse(Console.ReadLine()); } } Console.WriteLine("Second Matrix is :"); for (i = 0; i < 2; i++) { for (j = 0; j < 2; j++) { Console.Write(b[i, j] + "\t"); } Console.WriteLine(); } Console.WriteLine("Matrix Multiplication is :"); int[,] c = new int[m, n]; for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { c[i, j] = 0; for (int k = 0; k < 2; k++) { c[i, j] += a[i, k] * b[k, j]; } } } for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { Console.Write(c[i, j] + "\t"); } Console.WriteLine(); } } } }