CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace JagggedArrays
{
class Program
{
static void Main(string[] args)
{
const
int rows = 3;
//declare
the jagged array as 3 rows high
int
[][] x=new int[rows][];
// a row
with 2 elements
x[0]=new
int [2];
// a row
with 3 elements
x[1]=new
int[3];
// a row
with 4 elements
x[2]=new
int [4];
// fill
some (but not all) elements of the rows
x[0][1]=54;
x[1][0]=26;
x[1][1]=18;
x[2][0]=72;
x[2][3]=404;
for(int i=0;i<2;i++)
{
Console.WriteLine("This is jagged array 1 having
elements:[0][{0}]={1}",i,x[0][i]);
}
for(int i=0;i<3;i++)
{
Console.WriteLine("This is jagged array 2 having elements
:[1][{0}]={1}",i,x[1][i]);
}
for(int i=0;i<4;i++)
{
Console.WriteLine("This is jagged array 3 having elements
:[2][{0}]={1}",i,x[2][i]);
}
}
}
}
OUTPUT:
No comments:
Post a Comment