mirror of
https://github.com/svek95/programming_GB.git
synced 2026-05-17 18:41:44 +03:00
add HW8
This commit is contained in:
+55
-1
@@ -281,7 +281,61 @@
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public int[,] Task_54(int[,] array2d)
|
||||
{
|
||||
for (int i = 0; i < array2d.GetLength(0); i++)
|
||||
for (int j = 0; j < array2d.GetLength(1); j++)
|
||||
for (int k = 0; k < array2d.GetLength(1) - 1; k++)
|
||||
if (array2d[i, k] < array2d[i, k + 1])
|
||||
(array2d[i, k + 1], array2d[i, k]) = (array2d[i, k], array2d[i, k + 1]);
|
||||
|
||||
return array2d;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
int row = 0;
|
||||
public int Task_56(int[,] array2d)
|
||||
{
|
||||
|
||||
int summ = 0, summ1 = 0, summ2 = 0;
|
||||
|
||||
for(int i = 0; i < array2d.GetLength(0); i++)
|
||||
for(int j = 0; j < array2d.GetLength(1); j++)
|
||||
summ2 += array2d[i, j];
|
||||
if(summ2 < summ1)
|
||||
summ = summ2; row = i;
|
||||
summ1 = summ2;
|
||||
|
||||
return row;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public int[,] Task_62(int n)
|
||||
{
|
||||
int[,] snakeArray = new int[n, n];
|
||||
|
||||
int temp = 1;
|
||||
int i = 0, j = 0;
|
||||
|
||||
while (temp <= snakeArray.GetLength(0) * snakeArray.GetLength(1))
|
||||
{
|
||||
snakeArray[i, j] = temp;
|
||||
temp++;
|
||||
if (i <= j + 1 && i + j < snakeArray.GetLength(1) - 1)
|
||||
j++;
|
||||
else if (i < j && i + j >= snakeArray.GetLength(0) - 1)
|
||||
i++;
|
||||
else if (i >= j && i + j > snakeArray.GetLength(1) - 1)
|
||||
j--;
|
||||
else
|
||||
i--;
|
||||
}
|
||||
|
||||
return snakeArray;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -36,3 +36,8 @@
|
||||
- [X] Task_47
|
||||
- [X] Task_50
|
||||
- [X] Task_52
|
||||
|
||||
## HW7
|
||||
- [X] Task_54
|
||||
- [X] Task_56
|
||||
- [X] Task_62
|
||||
|
||||
@@ -37,8 +37,8 @@ public class Start
|
||||
Tools myTools = new Tools();
|
||||
|
||||
Console.Write("Wich task: ");
|
||||
Console.WriteLine("WH2 is 10, 13, 15");
|
||||
Console.WriteLine("WH3 is 19, 23");
|
||||
Console.WriteLine("WH8 is 54, 56, 62");
|
||||
// Console.WriteLine("WH3 is 19, 23");
|
||||
int taskNumver = Convert.ToInt32(Console.ReadLine());
|
||||
switch (taskNumver)
|
||||
{
|
||||
@@ -151,9 +151,33 @@ public class Start
|
||||
int[,] data52 = myTools.CreateRandom2dArray(4, 4, 0, 3);
|
||||
myTools.ShowInt2dArray(data52);
|
||||
HW.Task_52(data52);
|
||||
break;
|
||||
|
||||
|
||||
case 54:
|
||||
int[,] data54 = myTools.CreateRandom2dArray(5, 5, -10, 10);
|
||||
myTools.ShowInt2dArray(data54);
|
||||
Console.WriteLine("Res array is: ");
|
||||
myTools.ShowInt2dArray(HW.Task_54(data54));
|
||||
|
||||
break;
|
||||
|
||||
case 56:
|
||||
int[,] data56 = myTools.CreateRandom2dArray(5, 3, 0, 5);
|
||||
myTools.ShowInt2dArray(data56);
|
||||
Console.WriteLine(" ");
|
||||
Console.WriteLine("Max row is: " + HW.Task_56(data56));
|
||||
|
||||
break;
|
||||
|
||||
case 62:
|
||||
Console.WriteLine("Input N: ");
|
||||
int n = Convert.ToInt32(Console.ReadLine());
|
||||
myTools.ShowInt2dArray(HW.Task_62(n));
|
||||
break;
|
||||
|
||||
|
||||
|
||||
case 100:
|
||||
int[] data47 = myTools.RiadeLine4data();
|
||||
myTools.ShowInt2dArray(myTools.CreateRandom2dArray(data47[0], data47[1], data47[2], data47[3]));
|
||||
|
||||
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