0% found this document useful (0 votes)
13 views4 pages

Anshul

The document contains 3 code examples in C# demonstrating: 1) Creating and accessing an ArrayList to store different data types 2) Implementing a jagged array and accessing its elements 3) Defining a 3x3 matrix, transposing it, and printing the original and transposed matrices

Uploaded by

suraj nath
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views4 pages

Anshul

The document contains 3 code examples in C# demonstrating: 1) Creating and accessing an ArrayList to store different data types 2) Implementing a jagged array and accessing its elements 3) Defining a 3x3 matrix, transposing it, and printing the original and transposed matrices

Uploaded by

suraj nath
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Question – Create a array list in c# in which you can perform

different function of array list


Co-1 Bl-6

using System.Collections;
namespace ConsoleApp3
{
internal class Program
{
static void Main(string[] args)
{
var arrlist1 = new ArrayList();
arrlist1.Add (1);
arrlist1.Add (2.5);
arrlist1.Add ("Anshul Pundir");
foreach(var item in arrlist1)
{
Console.WriteLine(item);

}
Console.ReadKey();

}
}
}
Question – write a program for jagged array in c# ?
CO-1 BL-6
using System;

class JaggedArrayExample
{
static void Main()
{

int[][] jaggedArray = new int[3][];

jaggedArray[0] = new int[] { 1, 2, 3 };


jaggedArray[1] = new int[] { 4, 5, 6, 7 };
jaggedArray[2] = new int[] { 8, 9 };

Console.WriteLine("Jagged Array Elements:");

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


{
Console.Write($"Row {i + 1}: ");

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


{
Console.Write(jaggedArray[i][j] + " ");
}

Console.WriteLine();
}

Console.WriteLine("\nAccessing Individual Elements:");


Console.WriteLine("jaggedArray[1][2]: " + jaggedArray[1][2]);
Console.WriteLine("name:-Anshul Pundir\nclass MCA II(B) \nroll no 13");

Console.ReadLine();
}
}
Question – write a program in c# for 3x3 matrix and its transpose ?
CO-1 BL-6
using System;

class MatrixTranspose
{
static void Main()
{
// Declare and initialize a 3x3 matrix
int[,] matrix = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};

Console.WriteLine("Original Matrix:");
PrintMatrix(matrix);

// Transpose the matrix


int[,] transposedMatrix = TransposeMatrix(matrix);

Console.WriteLine("\nTransposed Matrix:");
PrintMatrix(transposedMatrix);

// Pause to see the output


Console.ReadLine();
}

// Function to transpose a 3x3 matrix


static int[,] TransposeMatrix(int[,] matrix)
{
int rows = matrix.GetLength(0);
int cols = matrix.GetLength(1);

int[,] result = new int[cols, rows];

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


{
for (int j = 0; j < cols; j++)
{
result[j, i] = matrix[i, j];
}
}

return result;
}

// Function to print a matrix


static void PrintMatrix(int[,] matrix)
{
int rows = matrix.GetLength(0);
int cols = matrix.GetLength(1);

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


{
for (int j = 0; j < cols; j++)
{
Console.Write(matrix[i, j] + "\t");
}
Console.WriteLine();
}
Console.WriteLine("name – Anshul Pundir \nclass = MCA II \nRoll no - 13");
}
}

You might also like