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.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace C_SHARP
{
class Program
{
static void Main(string[] args)
{
//a two dimensional array of numbers to store 5 rows and 6 columns.
int[,] numbers = new int[5, 6];
//Write a code to accept the data, assign it in array
for (int i = 0; i < 5; i++)
{
for (int j = 0;j < 6; j++)
{
Console.Write("Enter value [{0}][{1}]: ",i,j);
int.TryParse(Console.ReadLine(), out numbers[i,j]);
}
}
//print the data entered by the user.
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 6; j++)
{
Console.Write("{0,5} ", numbers[i, j]);
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
Comments
Leave a comment