Read 2D Array of size 3*3 and print the matrix

Hello,This is simple program to know use of multidimensional array.please go through it. I will update more programs on this on next blog.

Thank you.


 class Program
    {
        static void Main(string[] args)
        {
            int[,]Two_Dim = new int[3,3];
            int i, j;
            for(i = 0; i < 3; i++)
            {
                for(j = 0; j < 3; j++)
                {
                    Console.Write("element - [{0},{1}]:", i, j);
                    Two_Dim[i,j] = Convert.ToInt32(Console.ReadLine());
                }
            }
            for (i = 0; i < 3; i++)
            {
                Console.WriteLine("");
                for (j = 0; j < 3; j++)
                {
                    Console.Write("{0}\t", Two_Dim[i, j]);
                }
            }
            Console.ReadLine();
        }
    }


 Output:
element - [0,0]:1
element - [0,1]:2
element - [0,2]:3
element - [1,0]:4
element - [1,1]:5
element - [1,2]:6
element - [2,0]:7
element - [2,1]:8
element - [2,2]:9

1       2       3
4       5       6
7       8       9

No comments:

Post a Comment

Please let me know if you have any feedback or doubts.

Jagged Array

What is Jagged Array? Jagged array is called as "array of arrays". when you need a data inside your array element at that time you...