Skip to content

Commit

Permalink
solution from sem1 task 10, 13, 15
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaev63 committed Sep 8, 2023
1 parent 9ab5d0b commit a9d59e5
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Sem2Task10/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// №10 Напишите программу, которая принимает на вход трёхзначное число и
// на выходе показывает вторую цифру этого числа.
// 456 -> 5
// 782 -> 8
// 918 -> 1

// number generator from 100 to 1000
int num = new Random().Next(100, 1000);
Console.WriteLine(num);

// Creating an array of numbers to access them by index
char[] digitChar = num.ToString().ToCharArray();

// Take the second number from the array
Console.WriteLine("Вторая цифра числа " + digitChar[1]);
10 changes: 10 additions & 0 deletions Sem2Task10/Sem2Task10.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>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
50 changes: 50 additions & 0 deletions Sem2Task13/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// №13 Напишите программу, которая выводит третью цифру заданного числа или сообщает,
// что третьей цифры нет.
// 645 -> 5
// 78 -> третьей цифры нет
// 32679 -> 6
// * Сделать вариант для числа длиной до 10 цифр не используя char или string

void Variant1()
{
// Enter the number
Console.Write("Введите число: ");
int num = int.Parse(Console.ReadLine() ?? "0");

// Creating an array of numbers to access them by index
char[] numArray = num.ToString().ToCharArray();

// Condition for checking whether the number is three-digit
if (num >= 100)
{
Console.WriteLine("Трьтья цифра числа: " + numArray[2]);
}
else
{
Console.WriteLine("Третьей цифры нет!");
}
}

// * Сделать вариант для числа длиной до 10 цифр не используя char или string
void Variant2()
{
Console.Write("Введите число: ");
int num = int.Parse(Console.ReadLine() ?? "0");

if (num >= 100)
{
Console.WriteLine("Ошибка: ввод не более двухзначного числа!");
}
else if (num >= 10)
{
int secondDigit = num % 10; // We get the second digit of the number
Console.WriteLine("Вторая цифра числа: " + secondDigit);
}
else
{
Console.WriteLine("Второй цифры нет!");
}
}

Variant1();
Variant2();
10 changes: 10 additions & 0 deletions Sem2Task13/Sem2Task13.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>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
68 changes: 68 additions & 0 deletions Sem2Task15/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// №15 Напишите программу, которая принимает на вход цифру,
// обозначающую день недели, и проверяет, является ли этот день выходным.
// 6 -> да
// 7 -> да
// 1 -> нет
// * Сделать вариант с использованием конструкции Dictionary

void Variant1()
{
Console.Write("Введите число дня недели (1-7): ");
int numDay = int.Parse(Console.ReadLine() ?? "0");

// Creating a verification condition
if (numDay > 7) // If the input is greater than 7
{
Console.WriteLine("Ошибка: дней не может быть больше 7!");
}
else if (numDay >= 1 && numDay <= 5) // If the input is in the range from 1 to 5
{
Console.WriteLine("Рабочий день");
}
else // If the input is in the range from 6 to 7
{
Console.WriteLine("Выходной день!");
}
}

// * Сделать вариант с использованием конструкции Dictionary
void Variant2()
{
// Creating a dictionary
Dictionary<int, string> weekDays = new Dictionary<int, string>
{
{1, "Понедельник"},
{2, "Вторник"},
{3, "Среда"},
{4, "Четверг"},
{5, "Пятница"},
{6, "Суббота"},
{7, "Воскресенье"}
};

Console.Write("Введите число дня недели (1-7): ");
int numDay = int.Parse(Console.ReadLine() ?? "0");

// We check the correctness of entering a number from 1 to 7
if (numDay >= 1 && numDay <= 7)
{
string dayName = weekDays[numDay]; // We get the day of the week from the dictionary by the "key"

// Checking the day of the week
if (numDay >= 1 && numDay <= 5)
{
Console.WriteLine($"{dayName} - Рабочий день");
}
else
{
Console.WriteLine($"{dayName} - Выходной день!");
}
}
else // If the input is greater than 7
{
Console.WriteLine("Ошибка: дней не может быть больше 7!");
}
}

Variant1();
Variant2();
10 changes: 10 additions & 0 deletions Sem2Task15/Sem2Task15.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>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>

0 comments on commit a9d59e5

Please sign in to comment.