Aim:

To perform the jagged array program using c sharp.net application.

Algorithms:

Step1: Start the program

Step2: Open the new text document and type the program in the text document.

Step3: Create the class named “myjaggedArr”

Step4: Initialize the variable i, j, in the main function

Step5: Using the for loop condition, Initialize the i variable and  assign the zero value and made increment process until the condition (i<3) has reached false

Step6: Using the for loop condition the position will be placed as like a matrix

Step7: Save and compile the program.

Step8: Run the program.

Program:


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace myjaggedarr

{

class Program

    {

static void Main(string[] args)

        {

int[][] myjag = new int[3][];

for (int i = 0; i <myjag.Length; i++)

            {

myjag[i] = new int[i + 3];

            }

for (int i = 0; i < 3; i++)

            {

Console.WriteLine("enter the elements of row{0}:", i);

for (int j = 0; j <myjag[i].Length; j++)

                {

myjag[i][j] = int.Parse(Console.ReadLine());

                }

            }

int sum = 0;

for(int i=0;i<3;i++)

                {

for(int j=0;j<myjag[i].Length;j++)

                    {

sum+=myjag[i][j];

                    }

                }

Console.WriteLine("sum="+sum);

Console.Read();

        }

    }

}


OUTPUT:



BY
    REGU RAM SV.

Post a Comment

أحدث أقدم