0% found this document useful (0 votes)
29 views3 pages

3rd Lab

The document contains 12 programs demonstrating the use of arrays in C#. It defines multiple arrays, performs operations like sorting and reversing on the arrays, and retrieves values and indexes from the arrays.

Uploaded by

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

3rd Lab

The document contains 12 programs demonstrating the use of arrays in C#. It defines multiple arrays, performs operations like sorting and reversing on the arrays, and retrieves values and indexes from the arrays.

Uploaded by

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

using System;

namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
namespace arrys
{
class Program
{
static void Main(string[] args)
{
//program 1
/*
int[] arr1 = new int[5];
arr1[0] = 10;
arr1[1] = 20;
arr1[2] = 30;

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


{
Console.WriteLine(arr1[i]);
}
*/

//program 2
/*
int[] arr2 = new int[5] { 40, 50, 60, 70, 80 };
for (int i = 0; i < 5; i++)
{
Console.WriteLine(arr2[i]);
}
*/

//program 3
/*
int[] arr3 = new int[] { 90, 100, 110, 120, 130, 140 };
for (int i = 0; i < 6; i++)
{
Console.WriteLine(arr3[i]);
}
*/

//program 3
/*
int[,] arr4 = new int[2, 3] { { 1, 2, 3 }, { 11, 22, 33 } };

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


{
Console.WriteLine("\n");
for (int j = 0; j < 3; j++) {
Console.WriteLine(arr4[i,j]);
}
}
*/
// program 5
/*
int[,] arr5 = new int[,] { { 1, 2, 3 }, { 11, 22, 33 } };

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


{
Console.WriteLine("\n");
for (int j = 0; j < 3; j++)
{
Console.WriteLine(arr5[i, j]);
}
}
*/

// program 6

/*int max, min;


Random rnd = new Random((int)DateTime.Now.Ticks);
int[] dizi = new int[100];
for(int i = 0; i < 100; i++)

dizi[i] = rnd.Next();

max = dizi[0];
min = dizi[0];
for(int i = 1; i < 100; i++)
{
if (max < dizi[i])
max = dizi[i];
if (min > dizi[i])
min = dizi[i];
}
Console.WriteLine("Maximum is :{0} and Minimum is :{1}" ,max,
min);*/

// Program 7

/*int [] myarray = new int[5];


for (int i = 0; i < 5; i++)
myarray[i] = i;
foreach(int item in myarray)
{
Console.WriteLine(item);
}*/

// Program 8

/*const int nSat = 5;


const int nSut = 3;
int[,] dizi = new int[nSat, nSut];
for(int i = 0; i < nSat; i++)
{
for (int j = 0; j < nSut; j++)
{
dizi[i, j] = i * j;
Console.WriteLine(dizi[i, j]);
}

}*/
// Program 9

/* int[] arr = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
Console.WriteLine("Index");
Console.WriteLine(Array.IndexOf(arr, 5));
Console.WriteLine("Last index");
Console.WriteLine(Array.LastIndexOf(arr, 5));*/

// Program 10

/*string[] arr = { "Ali", "Bilal", "Ather", "saad" };


Array.Sort(arr);

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


{
Console.WriteLine(arr[i]);
}*/

// Program 11

/*int[] arr = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
Array.Reverse(arr);

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


{
Console.WriteLine(arr[i]);
}*/

// Program 12

int[] arr = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
Console.WriteLine("Index");
Console.WriteLine(Array.IndexOf(arr, 5));

Console.ReadLine();
}
}
}

You might also like