click here

C# Jagged Array

using System;
using System.Collections.Generic;
using System.Text;

namespace jaggedarray
{
class Program
{
static void Main(string[] args)
{
int[] c = new int[10];
Console.WriteLine("how many rows want to create");
int r = Convert.ToInt32(Console.ReadLine() );
int[][] a = new int[r][];
for(int i = 0 ; i
{
Console.WriteLine(" enter column for " + i + " row ");
c[i] = Convert.ToInt32(Console.ReadLine() );
a[i] = new int [c[i]];
}
Console.WriteLine(" enter values for jagged array" );
for (int k = 0; k < r; k++)
{
for (int j = 0; j < c[k]; j++)
{
a[k][j] = Convert.ToInt32(Console.ReadLine() );
}
}
Console.WriteLine(" jagged array ..." );
for (int l = 0; l < r; l++)
{
for (int m = 0; m < c[l]; m++)
{
Console.Write(a[l][m] + " ");
} Console.WriteLine();
}
Console.ReadLine();
}
} }

No comments:

Post a Comment