0% found this document useful (0 votes)
5 views5 pages

04 C# Assignment

The document contains multiple C# programs that perform various operations on integer arrays, including printing elements, finding the maximum and minimum values, checking if the array is sorted, summing elements, calculating the average, finding the second largest number, and comparing two arrays for equality. Each program defines a 'Main' method that initializes an array and calls a specific function to execute the desired operation. Some sections are marked with '???', indicating incomplete or unclear content.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

04 C# Assignment

The document contains multiple C# programs that perform various operations on integer arrays, including printing elements, finding the maximum and minimum values, checking if the array is sorted, summing elements, calculating the average, finding the second largest number, and comparing two arrays for equality. Each program defines a 'Main' method that initializes an array and calls a specific function to execute the desired operation. Some sections are marked with '???', indicating incomplete or unclear content.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1.

static void Main()


{
int[] num = { 10, 20, 30, 40, 50 };

Print(num);
}

static void Print(int[] num)


{

foreach (int element in num)


{
Console.WriteLine(element);
}
}
}

2. static void Main()


{
int[] num = { 10, 20, 30, 40, 50 };

FindMax(num);
}

static void FindMax(int[] num)


{
int max = num[0];
foreach (int i in num)
{
if (i > max)
{
max = i;
}
}

Console.WriteLine(max);
}
}
3. using System;

class Program
{
static void Main()
{
int[] num = { 10, 20, 30, 40, 50 };

FindMin(num);
}

static void FindMin(int[] num)


{
int min = num[0];
foreach (int i in num)
{
if (i < min)
{
min = i;
}
}

Console.WriteLine(min);
}
}

4. ‫؟؟؟‬

5. using System;

class Program
{
static void Main()
{
int[] num = { 1, 2, 3, 4, 5 };

Ascending(num);
}

static void Ascending(int[] num)


{
bool sorted = true;

for (int i = 0; i < num.Length - 1; i++)


{
if (num[i] > num[i + 1])
{
sorted = false;
break;
}
}

if (sorted)
{
Console.WriteLine("The array is sorted in ascending order.");
}
else
{
Console.WriteLine("The array is NOT sorted in ascending order.");
}
}
}

6.???

7. {
static void Main()
{
int[] numbers = { 5, 10, 15, 20 };
SumArray(numbers);
}

static void SumArray(int[] number)


{
int sum = 0;

foreach (int num in number)


{
sum += num;
}

Console.WriteLine(sum);
}
}

8. static void Main()


{
int[] numbers = { 10, 20, 30, 40, 50 };

FindAverage(numbers);
}

static void FindAverage(int[] arr)


{
int sum = 0;

foreach (int num in arr)


{
sum += num;
}

double average = (double)sum / arr.Length;

Console.WriteLine(average);
}
}
9.????

10. static void Main()


{
int[] num = { 10, 20, 30, 40, 50 };

FindSecondMax(num);
}

static void FindSecondMax(int[] num)


{
int max = num[0];
int secondMax = -1;

foreach (int i in num)


{
if (i > max)
{
secondMax = max;
max = i;
}
else if (i > secondMax && i < max)
{
secondMax = i;
}
}

Console.WriteLine("Second largest number is: " + secondMax);


}
}

11. ???
14. using System;
using System.Linq;

class Program
{
static void Main()
{
int[] array1 = { 10, 20, 30, 40 };
int[] array2 = { 10, 20, 30, 40 };

Console.WriteLine(AreArraysEqual(array1, array2));
}

static bool AreArraysEqual(int[] arr1, int[] arr2)


{
return arr1.SequenceEqual(arr2);
}
}

You might also like