-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |