Saturday 3 December 2016

C# JAGGED ARRAYS

using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;

namespace App4
{
classProgram
    {
staticvoid Main(string[] args)
        {
Console.WriteLine("Enter the number of arrays:");
int x = Convert.ToInt32(Console.ReadLine());
int[][] ar = newint[x][];

for (int i = 0; i < x; i++)
            {
Console.WriteLine("Enter the length of array: ");
int a = Convert.ToInt32(Console.ReadLine());
ar[i] = newint[a];
for (int y = 0; y < a; y++)
                {
Console.WriteLine("Enter Array ELEMENT !");
ar[i][y] = Convert.ToInt32(Console.ReadLine());
                }
            }

foreach (int[] d inar)
            {
foreach (int j in d)
                {
Console.Write(j);
                }
Console.WriteLine();
            }
Console.ReadLine();
        }
    }
}

OUTPUT

        Enter the number of arrays:

        2

        Enter the lenght of array:

        3

        Enter the Array Element !

        9

        Enter the Array Element !

        0



        Enter the Array Element !

        9

        Enter the lenght of array!

        2

        Enter the Array Element !

        2

        Enter the Array Element !

        2



        909

        22

No comments:

Post a Comment