mirror of
https://github.com/svek95/programming_GB.git
synced 2026-05-17 18:41:44 +03:00
add HW5
This commit is contained in:
+49
@@ -2,6 +2,7 @@
|
||||
{
|
||||
class HomeWork
|
||||
{
|
||||
Practics pract = new Practics();
|
||||
int resaultHW;
|
||||
private int counter;
|
||||
|
||||
@@ -151,6 +152,54 @@
|
||||
|
||||
Console.WriteLine("Array is: " + "[{0}]", string.Join(", ", array));
|
||||
}
|
||||
|
||||
public int Task_34(int[] array)
|
||||
{
|
||||
counter = 0;
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
if (array[i] % 2 == 0)
|
||||
counter++;
|
||||
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
|
||||
public int Task_36(int[] array)
|
||||
{
|
||||
resaultHW = 0;
|
||||
for (int i = 1; i < array.Length; i++)
|
||||
{
|
||||
if (i % 2 != 1)
|
||||
resaultHW += array[i];
|
||||
|
||||
}
|
||||
return resaultHW;
|
||||
}
|
||||
|
||||
public void Task_38(int[] array)
|
||||
{
|
||||
resaultHW = 0;
|
||||
int maxElement = array[0];
|
||||
int minElement = array[0];
|
||||
for (int i = 1; i < array.Length; i++)
|
||||
{
|
||||
if (maxElement < array[i])
|
||||
{
|
||||
maxElement = array[i];
|
||||
}
|
||||
if (minElement > array[i])
|
||||
{
|
||||
minElement = array[i];
|
||||
}
|
||||
|
||||
resaultHW = maxElement - minElement;
|
||||
|
||||
}
|
||||
Console.WriteLine($"\nDev between max element ({maxElement}) and min ({minElement}) is: {resaultHW}");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ public class Start
|
||||
static void MyTask()
|
||||
{
|
||||
HomeWork HW = new HomeWork();
|
||||
Practics pract = new Practics();
|
||||
|
||||
Console.Write("Wich task: ");
|
||||
Console.WriteLine("WH2 is 10, 13, 15");
|
||||
@@ -82,6 +83,32 @@ public class Start
|
||||
Console.WriteLine("Length for array: ");
|
||||
HW.Task_29(ReadIntNumber());
|
||||
break;
|
||||
case 34:
|
||||
Console.WriteLine("Input size mass");
|
||||
int size = Convert.ToInt32(Console.ReadLine());
|
||||
int min = 100;
|
||||
int max = 999;
|
||||
Console.WriteLine("Evan's number is: " + HW.Task_34(pract.newRandomMass(size, min, max)));
|
||||
break;
|
||||
case 36:
|
||||
Console.WriteLine("Input size mass");
|
||||
int size1 = Convert.ToInt32(Console.ReadLine());
|
||||
Console.WriteLine("Input min");
|
||||
int min1 = Convert.ToInt32(Console.ReadLine());
|
||||
Console.WriteLine("Input max");
|
||||
int max1 = Convert.ToInt32(Console.ReadLine());
|
||||
Console.WriteLine("Summ is: " + HW.Task_36(pract.newRandomMass(size1, min1, max1)));
|
||||
break;
|
||||
case 38:
|
||||
Console.WriteLine("Input size mass");
|
||||
int size2 = Convert.ToInt32(Console.ReadLine());
|
||||
Console.WriteLine("Input min");
|
||||
int min2 = Convert.ToInt32(Console.ReadLine());
|
||||
Console.WriteLine("Input max");
|
||||
int max2 = Convert.ToInt32(Console.ReadLine());
|
||||
//Console.WriteLine("Summ is: " + HW.Task_38(pract.newRandomMass(size2, min2, max2)));
|
||||
HW.Task_38(pract.newRandomMass(size2, min2, max2));
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user