Wednesday, 27 November 2013

C# Matrx Multiplication Program using Multidimensional Array-----------||||||||||||

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ArrayMatrixMultiplication
{

    class Program
    {
        static int ROWS=3;
        static int COLUMNS=3;
     
       

     

       
       
        static void Main(string[] args)
        {
            int [,] a=new int[ROWS,COLUMNS];
            Console.WriteLine("\n Enter Your First Matrix");
            for (int i = 0; i < ROWS; i++)
            {
                for (int j = 0; j < COLUMNS; j++)
                {
                    a[i, j] = int.Parse(Console.ReadLine());
                }
            }
                int [,] b=new int[ROWS,COLUMNS];
                Console.WriteLine("Enter Your Second Matrix");
                for (int i = 0; i < ROWS; i++)
                {
                    for (int j = 0; j < COLUMNS; j++)
                    {
                        b[i, j] = int.Parse(Console.ReadLine());
                    }
                }
                int[,] c = new int[ROWS, COLUMNS];
                Console.WriteLine("Matrix Multiplication Is");
                Console.WriteLine("\n");
              
                for (int i = 0; i < ROWS; i++)
                {
                    for (int j = 0; j < COLUMNS; j++)
                    {
                        for (int k = 0; k < 3; k++)
                        {
                            c[i, j] = 0;
           
                            c[i, j]  = a[i, k] * b[k, j];
                           
                            Console.Write(c[i,j]+" ");
                           
                        }
                        Console.WriteLine("  ");
                    }
                    Console.ReadKey();
                }
              

        }
    }
}


Output:

No comments:

Post a Comment