diff --git a/HomeWork.cs b/HomeWork.cs index 6e6482c..b316ba4 100644 --- a/HomeWork.cs +++ b/HomeWork.cs @@ -152,6 +152,11 @@ Console.WriteLine("Array is: " + "[{0}]", string.Join(", ", array)); } + + public void PrintArray(double[] array) + { + Console.WriteLine("[{0}]", string.Join(", ", array)); + } public int Task_34(int[] array) { @@ -197,9 +202,87 @@ } Console.WriteLine($"\nDev between max element ({maxElement}) and min ({minElement}) is: {resaultHW}"); + } + + public int[] craeteMass(int size) + { + int[] array = new int[size]; + + for (int i = 0; i < array.Length; i++) + { + Console.WriteLine($"Input {i+1} number: "); + int number = Convert.ToInt32(Console.ReadLine()); + array[i] = number; + } + + return array; } + public int Tak_41(int[] array) + { + counter = 0; + for (int i = 0; i < array.Length; i++) + { + if(array[i] > 0 ) counter += 1; + } + return counter; + } + + public double[] Task_43(double b1, double k1, double b2, double k2) + { + double x = (b2 - b1) / (k1 - k2); + double y = k1 * x + b1; + double[] dotCross = new[] {x, y}; + + return dotCross; + + // Console.WriteLine("x = " + x + "y = " + y ); + + } + + public double[,] Task_47(int rows, int columns) + { + Random rand = new Random(); + double[,] newArray = new double[rows, columns]; + Console.WriteLine(" "); + for (int i = 0; i < rows; i++) + for (int k = 0; k < columns; k++) + newArray[i, k] = rand.Next(-100, 200) + rand.Next(0, 9) / 10.0; + return newArray; + + } + + + public void Task_50(int[,] array, int rowsIndex, int columnsIndex) + { + if (rowsIndex > array.GetLength(0) || columnsIndex > array.GetLength(1)) + Console.WriteLine($"Not element in array in [{rowsIndex},{columnsIndex}]"); + + else + Console.WriteLine("Element in [{rowsIndex},{columnsIndex}] is: " + array[rowsIndex, columnsIndex]); + + } + + public void Task_52(int[,] array) + { + for (int i = 0; i < array.GetLength(0); i++) + { + int meanArray = 0; + int ColChetn = 0; + for (int k = 0; k < array.GetLength(1); k++) + { + meanArray += array[k, i]; + + } + + Console.WriteLine($"Arithmetic mean of column elements {i + 1} = {(float)meanArray / array.GetLength(1)}"); + + } + + } + + diff --git a/README.md b/README.md index 4764db3..66402f5 100644 --- a/README.md +++ b/README.md @@ -27,3 +27,12 @@ - [X] Task_34 - [X] Task_36 - [X] Task_38 + +## HW6 +- [X] Task_41 +- [X] Task_43 + +## HW7 +- [X] Task_47 +- [X] Task_50 +- [X] Task_52 diff --git a/Start.cs b/Start.cs index c4a3b88..bcf4adf 100644 --- a/Start.cs +++ b/Start.cs @@ -34,6 +34,7 @@ public class Start { HomeWork HW = new HomeWork(); Practics pract = new Practics(); + Tools myTools = new Tools(); Console.Write("Wich task: "); Console.WriteLine("WH2 is 10, 13, 15"); @@ -109,6 +110,56 @@ public class Start //Console.WriteLine("Summ is: " + HW.Task_38(pract.newRandomMass(size2, min2, max2))); HW.Task_38(pract.newRandomMass(size2, min2, max2)); break; + case 41: + Console.WriteLine("Input M numbers"); + int size3 = Convert.ToInt32(Console.ReadLine()); + Console.WriteLine("Numbers more then 0 is: "+HW.Tak_41(HW.craeteMass(size3))); + break; + case 43: + Console.WriteLine("Input b1"); + int b1 = Convert.ToInt32(Console.ReadLine()); + Console.WriteLine("Input k1"); + int k1 = Convert.ToInt32(Console.ReadLine()); + Console.WriteLine("Input b2"); + int b2 = Convert.ToInt32(Console.ReadLine()); + Console.WriteLine("Input k2"); + int k2 = Convert.ToInt32(Console.ReadLine()); + Console.Write("Dot Cross is:"); + HW.PrintArray(HW.Task_43(b1, k1, b2, k2)); + break; + + case 47: + Console.WriteLine("Input number of rows: "); + int rows = Convert.ToInt32(Console.ReadLine()); + Console.WriteLine("Input number of columns: "); + int columns = Convert.ToInt32(Console.ReadLine()); + myTools.ShowDoublet2dArray(HW.Task_47(rows, columns)); + + break; + + case 50: + int[,] data50 = myTools.CreateRandom2dArray(5, 5, -10, 10); + myTools.ShowInt2dArray(data50); + Console.WriteLine("Input indexRows: "); + int indexRows = Convert.ToInt32(Console.ReadLine()); + Console.WriteLine("Input indexColumns: "); + int indexColumns = Convert.ToInt32(Console.ReadLine()); + HW.Task_50(data50, indexRows, indexColumns); + break; + + case 52: + int[,] data52 = myTools.CreateRandom2dArray(4, 4, 0, 3); + myTools.ShowInt2dArray(data52); + HW.Task_52(data52); + + break; + + case 100: + int[] data47 = myTools.RiadeLine4data(); + myTools.ShowInt2dArray(myTools.CreateRandom2dArray(data47[0], data47[1], data47[2], data47[3])); + + + break; default: @@ -120,8 +171,10 @@ public class Start } static void PracticsTask() + { Practics pract = new Practics(); + Tools myTools = new Tools(); Console.Write("Wich task: "); int taskNumver = Convert.ToInt32(Console.ReadLine()); @@ -202,6 +255,24 @@ public class Start Console.WriteLine("Rwsault is: "); pract.printArray(pract.fibanach(number10)); break; + + case 12: + Console.WriteLine("FInput number of rows: "); + int rows = Convert.ToInt32(Console.ReadLine()); + Console.WriteLine("Input number of columns: "); + int columns = Convert.ToInt32(Console.ReadLine()); + Console.WriteLine("Third min"); + int min2d = Convert.ToInt32(Console.ReadLine()); + Console.WriteLine("Third max"); + int max2d = Convert.ToInt32(Console.ReadLine()); + int[,] myArray = myTools.CreateRandom2dArray(rows, columns, min2d, max2d); + myTools.ShowInt2dArray(myArray); + Console.WriteLine(" "); + Console.WriteLine("Resault:"); + int[,] myArrayRev = pract.Task1_8(myArray); + myTools.ShowInt2dArray(myArrayRev); + + break; default: Console.WriteLine("Wrong task"); diff --git a/Tools.cs b/Tools.cs new file mode 100644 index 0000000..db8cc9e --- /dev/null +++ b/Tools.cs @@ -0,0 +1,62 @@ +namespace pr; + +public class Tools +{ + + public int[] RiadeLine4data() + { + + Console.WriteLine("FInput number of rows: "); + int rows = Convert.ToInt32(Console.ReadLine()); + Console.WriteLine("Input number of columns: "); + int columns = Convert.ToInt32(Console.ReadLine()); + Console.WriteLine("Third min"); + int min2d = Convert.ToInt32(Console.ReadLine()); + Console.WriteLine("Third max"); + int max2d = Convert.ToInt32(Console.ReadLine()); + + int[] return4Data = new[] { rows, columns, min2d, max2d }; + + return return4Data; + + } + + public int[,] CreateRandom2dArray(int rows, int columns, int minElement, int maxElement) + { + int[,] newArray = new int[rows, columns]; + Console.WriteLine(" "); + for (int i = 0; i < rows; i++) + for (int k = 0; k < columns; k++) + newArray[i, k] = new Random().Next(minElement, maxElement + 1 ); + return newArray; + + } + + public void ShowInt2dArray(int[,] array) + { + for (int i = 0; i < array.GetLength(0); i++) + { + for (int k = 0; k < array.GetLength(1); k++) + Console.Write("{0,3}", array[i, k]+ " "); + Console.WriteLine(); + } + + + } + + public void ShowDoublet2dArray(double[,] array) + { + for (int i = 0; i < array.GetLength(0); i++) + { + for (int k = 0; k < array.GetLength(1); k++) + Console.Write("{0,3}", array[i, k]+ " "); + Console.WriteLine(); + } + + + } + + + + +} \ No newline at end of file diff --git a/bin/Debug/net6.0/programming_GB.dll b/bin/Debug/net6.0/programming_GB.dll index 3b72078..afaf36a 100644 Binary files a/bin/Debug/net6.0/programming_GB.dll and b/bin/Debug/net6.0/programming_GB.dll differ diff --git a/bin/Debug/net6.0/programming_GB.pdb b/bin/Debug/net6.0/programming_GB.pdb index 827b1b6..c30ddae 100644 Binary files a/bin/Debug/net6.0/programming_GB.pdb and b/bin/Debug/net6.0/programming_GB.pdb differ diff --git a/obj/Debug/net6.0/programming_GB.csproj.CoreCompileInputs.cache b/obj/Debug/net6.0/programming_GB.csproj.CoreCompileInputs.cache index 240b3d8..9cd2b4e 100644 --- a/obj/Debug/net6.0/programming_GB.csproj.CoreCompileInputs.cache +++ b/obj/Debug/net6.0/programming_GB.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -1cea4dc6da66272d27938ece339a31c45c8e4364 +1a10cf6e18fc3b5ef76d1e32c50a876abd8d08f3 diff --git a/obj/Debug/net6.0/programming_GB.dll b/obj/Debug/net6.0/programming_GB.dll index 3b72078..afaf36a 100644 Binary files a/obj/Debug/net6.0/programming_GB.dll and b/obj/Debug/net6.0/programming_GB.dll differ diff --git a/obj/Debug/net6.0/programming_GB.pdb b/obj/Debug/net6.0/programming_GB.pdb index 827b1b6..c30ddae 100644 Binary files a/obj/Debug/net6.0/programming_GB.pdb and b/obj/Debug/net6.0/programming_GB.pdb differ diff --git a/obj/Debug/net6.0/ref/programming_GB.dll b/obj/Debug/net6.0/ref/programming_GB.dll index 9df3791..dd3ceee 100644 Binary files a/obj/Debug/net6.0/ref/programming_GB.dll and b/obj/Debug/net6.0/ref/programming_GB.dll differ diff --git a/obj/Debug/net6.0/refint/programming_GB.dll b/obj/Debug/net6.0/refint/programming_GB.dll index 9df3791..dd3ceee 100644 Binary files a/obj/Debug/net6.0/refint/programming_GB.dll and b/obj/Debug/net6.0/refint/programming_GB.dll differ