Wednesday, 26 December 2012

Write a program to ADD Two Matrix in C#

Yes here ,I am writing a program in C# to add two matrix.

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

namespace ConsoleApplication1
{
    class AddTwo_Matrix
    {
        static void Main(string[] args)
        {
            int[,] a = { { 1, 3, 4 }, { 2, 4, 7 }, { 3, 5, 6 } };
            int[,] b = { { 3, 5, 5 }, { 4, 5, 6 }, { 2, 7, 8 } };
            int[,] c = new int[3,3];
            int f = c.Length;
            int i, m = 0;
            int j = 0, n = 0;
            for (i = 0; i < 3; i++)
            {
                Console.WriteLine("");
                for (j = 0; j < 3; j++)
                {
                    Console.WriteLine(""+a[i,j]);
                }
            }
            Console.WriteLine("\n");
            for (m = 0; m < 3; m++)
            {
                Console.WriteLine("");
                for (n = 0; n < 3; n++)
                {
                    Console.WriteLine(""+b[m,n]);
                }
            }
            Console.WriteLine("\n");
            for (int k = 0; k < 3; k++)
            {
                Console.WriteLine("");
                for (int l = 0; l < 3; l++)
                {
                    Console.WriteLine(a[k,l]+b[k,l]+"\t");
                }
            }
            Console.WriteLine("yes it is Solved ,its very easy to add two matrix");
            Console.Read();

        }
    }
}

No comments:

Post a Comment