Skip to content
Binary file modified .DS_Store
Binary file not shown.
11 changes: 11 additions & 0 deletions 4KindsMethods/4KindsMethods.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>_4KindsMethods</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
52 changes: 52 additions & 0 deletions 4KindsMethods/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 4 kinds of common Methods overview

void Method1()
{
Console.WriteLine("Автор...");
}
Method1();


void Method2(string msg)
{
Console.WriteLine(msg);
}
Method2("Текст сообщения");

void Method21(string msg, int count)
{
int i = 0;
while (i < count)
{
Console.WriteLine(msg);
i++;
}

}
Method21(count: 4, msg: "Текст"); // Для именованных переменных порядок значения не имеет. Count - сколько раз.


int Method3()
{
return DateTime.Now.Year;
}

int year = Method3();
Console.WriteLine(year);


string Method4(int count, string c) // Вместо string тут можно char
{
int i = 0;
string result = String.Empty;

while(i < count)
{
result = result + c;
i++;
}
return result;
}

string res = Method4(10, "some_text ");
Console.WriteLine(res);
10 changes: 10 additions & 0 deletions ArraySorting/ArraySorting.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
37 changes: 37 additions & 0 deletions ArraySorting/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Упорядочить данные внутри массива методом выбора (от минимального к максимальному).

int[] arr = {5, 2, 1, 6, 8, 20, 7, 2, 23, 3, 1};

void PrintArray(int[] array)
{
int count = array.Length;
for (int i = 0; i < count; i++)
{
Console.Write($"{array[i]} "); // Вывели массив
}
Console.WriteLine();
}

void SelectionSort(int[] array)
{
for (int i = 0; i < array.Length; i++)
{
int minPosition = i;

for(int j = i + 1; j < array.Length; j++) // На лекции было (array.Length - 1), но так первый эл-т встает в конец
{
if (array[j] < array[minPosition])
{
minPosition = j;
}
}
int temporary = array[i];
array[i] = array[minPosition];
array[minPosition] = temporary;
Console.Write($"{array[i]} "); // Вывели массив
}
Console.WriteLine();
}

PrintArray(arr);
SelectionSort(arr);
10 changes: 10 additions & 0 deletions DoubleArray/DoubleArray.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
55 changes: 55 additions & 0 deletions DoubleArray/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Двумерные массивы

string[,] table = new string[5, 8]; // по умолчанию String.Empty

for(int rows = 0; rows < 5; rows++)
{
for(int columns = 0; columns < 8; columns++)
{
Console.Write($"{table[rows, columns]}");
}
Console.WriteLine(); // Разрыв для аккуратности вывода
}


int[,] matrix = new int [3,4]; // По умолчанию заполняется 0
matrix[1,2] = 15; // обратились к элементу и изменили его

for(int rows = 0; rows < matrix.GetLength(0); rows++)
{
for(int columns = 0; columns < matrix.GetLength(1); columns++)
{
Console.Write($"{matrix[rows, columns]}");
}
Console.WriteLine();
}


int[,] array = new int[4,7];
void PrintArray(int[,] arr)
{
for(int i = 0; i < arr.GetLength(0); i++)
{
for(int j = 0; j < arr.GetLength(1); j++)
{
Console.Write($"{arr[i, j]}");
}
Console.WriteLine();
}
}

void FillArray(int[,] arr)
{
for(int i = 0; i < arr.GetLength(0); i++)
{
for(int j = 0; j < arr.GetLength(1); j++)
{
arr[i, j] = new Random().Next(1, 10);
}
}
}

FillArray(array);
Console.WriteLine();
PrintArray(array);
Console.WriteLine();
10 changes: 10 additions & 0 deletions Factorial/Factorial.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
20 changes: 20 additions & 0 deletions Factorial/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Факториал через рекурсию

double Factorial (int n) // Тип int переполянется на 17, надо заменить на double
{
if(n == 1)
{
return 1;
}
else
{
return n * Factorial(n - 1);
}
}

Console.WriteLine(Factorial(40));

for(int i = 1; i < 40; i++) // Проверка работы алгоритма, вывод всех чисел ДО искомого
{
Console.WriteLine($"{i}! = {Factorial(i)}");
}
10 changes: 10 additions & 0 deletions Fibonacci/Fibonacci.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
25 changes: 25 additions & 0 deletions Fibonacci/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Числа Фибоначчи

int Fibonacci(int n)
{
/*
if(n == 0)
{
return 0;
}
if(n == 1 || n == 2)
{
return 1;
}
*/
if (n == 0 || n == 1)
{
return n;
}
return Fibonacci(n - 1) + Fibonacci(n - 2);
}

for(int i = 0; i < 17; i++) // Число можно задать любое, после 40 начнет работать медленно из-за затрат ресурсов
{
Console.WriteLine(Fibonacci(i));
}
10 changes: 10 additions & 0 deletions HW10/HW10.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
32 changes: 32 additions & 0 deletions HW10/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Принять трёхзначное число, вывести 2й знак

void FillArray(int[] numbers) // Рассматриваем число как массив - создаем и заполняем массив
{
int length = numbers.Length;
int index = 0;
while(index < length)
{
numbers[index] = new Random().Next(1,9);
index++;
}
}

void PrintArray(int[] nums)
{
int count = nums.Length;
int ind = 0;
while(ind < count)
{
Console.Write(nums[ind]);
ind++;
}
}


int[] array = new int[3];

FillArray(array);
PrintArray(array);

Console.WriteLine(":");
Console.WriteLine(array[1]);
10 changes: 10 additions & 0 deletions HW13/HW13.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
22 changes: 22 additions & 0 deletions HW13/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Вывести 3-й знак заданного числа или сообщить, что 3-его знака нет (для двузначных чисел и цифр)

class Program
{
static void Main(string[] args)
{
// 1st method
Console.WriteLine("Введите Ваше число: ");
// 2nd method
string? userNumber = Console.ReadLine();
Console.WriteLine(ThirdChar(userNumber));
}

static string ThirdChar(string? userNumber)
{
if (userNumber?.Length > 2)
{
return $"Третий знак - {userNumber[2]}";
}
return "Третьего знака нет!";
}
}
10 changes: 10 additions & 0 deletions HW15/HW15.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
21 changes: 21 additions & 0 deletions HW15/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Принять на вход цифру, обозначающую день недели, и проверить, выходной ли это день.


class Program
{
static void Main(string[] args)
{
Console.WriteLine("Введите день недели (цифру от 1 до 7): ");
string? day = Console.ReadLine();
Console.WriteLine(usersDay(day));
}

static string usersDay(string? day)
{
if (day == "6" || day == "7")
{
return "День выходной";
}
return "День будний";
}
}
10 changes: 10 additions & 0 deletions HW35/HW35.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
Loading