Saturday 16 April 2016

Write a console application for multiplication of Matrix.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4
{
class Program
    {
static void Main(string[] args)
        {
int i, j;
int[,] a = new int[3, 3];
Console.WriteLine("Enter no for matrix");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
a[i, j] = int.Parse(Console.ReadLine());
}
}
int[,] b = new int[3, 3];
Console.WriteLine("Enter no for 2 matrix");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
b[i, j] = int.Parse(Console.ReadLine());
}
}
Console.WriteLine("Multiplication is:");
int[,] c = new int[3, 3];
for (i = 0; i < 3; i++)
            {
for (j = 0; j < 3; j++)
                {
c[i, j] = 0;
for (int k = 0; k < 3; k++)
                    {
c[i, j] += a[i, k] * b[k, j];
                    }
                }
         }
for (i = 0; i < 3; i++)
         {
for (j = 0; j < 3; j++)
                {
Console.Write(c[i, j] + "\t");
                }
Console.WriteLine();
            }
Console.ReadKey();
        }
    }
}

No comments:

Post a Comment