using System;
class Program
{
static void Main()
{
Console.WriteLine("Please enter the number of element");
int NoOfElement = int.Parse(Console.ReadLine());
int[][] jaggedArray = new int[NoOfElement][];
Console.WriteLine("Initializing each element in Jagged Array");
for (int i = jaggedArray.GetLowerBound(0); i <= jaggedArray.GetUpperBound(0); i++)
{
Console.WriteLine("Please Enter the number of element in Row : {0}", i + 1);
int colsize = int.Parse(Console.ReadLine());
jaggedArray[i] = new int[colsize];
Console.WriteLine("Reading Data in Jagged Array");
for (int j = jaggedArray[i].GetLowerBound(0); j <= jaggedArray[i].GetUpperBound(0); j++)
{
Console.WriteLine("Please enter the value [{0} {1}]",i,j);
jaggedArray[i][j] = int.Parse(Console.ReadLine());
}
}
Console.Clear();
Console.WriteLine("Displaying the jagged array Element");
foreach (int[] elementArray in jaggedArray)
{
foreach (int element in elementArray)
{
Console.Write(element + "\t");
}
Console.WriteLine("\n");
}
}
}
class Program
{
static void Main()
{
Console.WriteLine("Please enter the number of element");
int NoOfElement = int.Parse(Console.ReadLine());
int[][] jaggedArray = new int[NoOfElement][];
Console.WriteLine("Initializing each element in Jagged Array");
for (int i = jaggedArray.GetLowerBound(0); i <= jaggedArray.GetUpperBound(0); i++)
{
Console.WriteLine("Please Enter the number of element in Row : {0}", i + 1);
int colsize = int.Parse(Console.ReadLine());
jaggedArray[i] = new int[colsize];
Console.WriteLine("Reading Data in Jagged Array");
for (int j = jaggedArray[i].GetLowerBound(0); j <= jaggedArray[i].GetUpperBound(0); j++)
{
Console.WriteLine("Please enter the value [{0} {1}]",i,j);
jaggedArray[i][j] = int.Parse(Console.ReadLine());
}
}
Console.Clear();
Console.WriteLine("Displaying the jagged array Element");
foreach (int[] elementArray in jaggedArray)
{
foreach (int element in elementArray)
{
Console.Write(element + "\t");
}
Console.WriteLine("\n");
}
}
}
No comments:
Post a Comment