-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
74 lines (62 loc) · 2.15 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Collections.Generic;
using System.Diagnostics.Eventing.Reader;
using System.Linq;
using System.Text;
using System.Globalization;
using System.Threading.Tasks;
using System.Linq.Expressions;
namespace Uroks
{
internal class Program
{
static void Main(string[] args)
{
Console.Write("The length of the array: ");
int.TryParse(Console.ReadLine(), out int arrayLength);
if (arrayLength <= 0)
{
Console.WriteLine("\nInvalid array length");
return;
}
int[] myArray = new int[arrayLength];
for (int i = 0; i < arrayLength; i++)
{
Console.Write(i + " element of array: ");
if(!int.TryParse(Console.ReadLine(), out myArray[i]))
{
Console.WriteLine("I can't write an array number");
return;
}
}
Console.Write("\nYour array is in the opposite direction: ");
for (int i = arrayLength - 1; i >= 0; i--)
{
Console.Write(myArray[i] + " ");
}
int sumCount = 0;
for (int i = 0; i < arrayLength; i++)
{
if (myArray[i] % 2 == 0)
{
sumCount = sumCount + myArray[i];
}
}
Console.WriteLine("\nThe sum of the even numbers of the array = " + sumCount);
int smallerNum = myArray[0], biggestNum = myArray[0];
for (int i = 1; i < arrayLength; i++)
{
if (myArray[i] < smallerNum)
{
smallerNum = myArray[i];
}
if (myArray[i] > biggestNum)
{
biggestNum = myArray[i];
}
}
Console.WriteLine("The smallest number of the array = " + smallerNum);
Console.WriteLine("The biggest number of the array = " + biggestNum);
}
}
}