Answer to Question #320894 in C# for VJSY

Question #320894

Write a program to define a two dimensional array of numbers to store 5 rows and 6 columns. 

Write a code to accept the data, assign it in array, and print the data entered by the user. 


1
Expert's answer
2022-03-30T14:10:09-0400
using System;

namespace two_dim_arr
{
    class Program
    {
        public static void Main(string[] args)
        {
            int[,] array = new int[5,6];
            string[] tokens;
            string str;
            Console.WriteLine("Enter array:");
            for (int i = 0; i<5; i++)
            {
                Console.WriteLine("Enter row {0} (sep. space):", i+1);
                str = Console.ReadLine();
                tokens = str.Split(' ');
                for (int j=0; j<6; j++)
                    array[i,j]= Convert.ToInt32(tokens[j]);
            }
            Console.WriteLine();
            Console.WriteLine("Two dimensional array:");
            for (int i = 0; i<5; i++)
            {
                for (int j = 0; j<6; j++)
                    Console.Write("{0} ", array[i,j]);
                Console.WriteLine();                    
            }
            
            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS