Professional Documents
Culture Documents
[Arrays]
Task No.1:
Make a program in C# to print name of Days Using Dense Array.
CODE:
string[] Days_Of_Week = { "Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday", "Sunday" };
for (int i = 0; i <= 6; i++)
{
Console.WriteLine(Days_Of_Week[i]);
}
Output:
[Arrays]
Task No.2:
Write a program, which creates an array of 20 elements of type integer and
initializes each of the elements with a value equals to the index of the element
multiplied by 5. Print the elements to the console.
CODE:
int[] arr = new int[20];
Output:
[Arrays]
Task No.3:
Write a program, which reads two arrays from the console and checks whether
they are equal (two arrays are equal when they are of equal length and all of
their elements, which have the same index, are equal).
CODE:
bool arraysEqual = true;
[Arrays]
Output:
[Arrays]
Task No.4:
Make a program in C# in which take 5 numbers from user and then give sum
and avg. of them. Using arrays.
CODE:
Console.WriteLine("For how many numbers you want to calculate average? ");
int numbersForAverage = int.Parse(Console.ReadLine());
double[] myArrayOfNumbers = new double[numbersForAverage];
Console.WriteLine("Input your numbers");
for (int i = 0; i < myArrayOfNumbers.Length; i++)
{
myArrayOfNumbers[i] = int.Parse(Console.ReadLine());
}
double sum = 0;
for (int j = 0; j < myArrayOfNumbers.Length; j++)
{
sum += myArrayOfNumbers[j];
}
double averageOfNumbers = sum / numbersForAverage;
Console.WriteLine("The average of your numbers is: {0}",
averageOfNumbers);
Console.ReadLine();
Output: