Implemented Task1 and Task2 solutions

This commit is contained in:
Egor 2022-07-18 17:00:09 +03:00
parent 5272fcdabf
commit a26d47e462
6 changed files with 104 additions and 2 deletions

View file

@ -1,2 +1,22 @@
// See https://aka.ms/new-console-template for more information Console.WriteLine("Вычисление квадратного корня");
Console.WriteLine("Hello, World!"); while (true)
{
Console.Write("Введите число: ");
string? input = Console.ReadLine();
bool isInputNumeric = double.TryParse(input, out double inputNumber);
if (!isInputNumeric)
{
Console.WriteLine($"Ошибка: '{input}' не является числом");
continue;
}
if (inputNumber < 0)
{
Console.WriteLine("Ошибка: корень отрицательного числа вычислить невозможно");
continue;
}
double result = Math.Sqrt(inputNumber);
Console.WriteLine($"Результат вычислений: {result}");
Console.WriteLine();
}

31
Task2/Task2.sln Normal file
View file

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.32407.343
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Task2Lib", "Task2\Task2Lib.csproj", "{E918BF0C-4A2D-4EB6-9A2E-C9C55AC741B0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Task2App", "Task2App\Task2App.csproj", "{1E07724A-EB97-4297-86F4-270DC319FA3F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E918BF0C-4A2D-4EB6-9A2E-C9C55AC741B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E918BF0C-4A2D-4EB6-9A2E-C9C55AC741B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E918BF0C-4A2D-4EB6-9A2E-C9C55AC741B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E918BF0C-4A2D-4EB6-9A2E-C9C55AC741B0}.Release|Any CPU.Build.0 = Release|Any CPU
{1E07724A-EB97-4297-86F4-270DC319FA3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1E07724A-EB97-4297-86F4-270DC319FA3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1E07724A-EB97-4297-86F4-270DC319FA3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1E07724A-EB97-4297-86F4-270DC319FA3F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {246036BD-DB2E-4BEB-8ACD-D79B25B86A46}
EndGlobalSection
EndGlobal

View file

@ -0,0 +1,7 @@
namespace Task2Lib
{
public static class Calculations
{
public static double AverageOf3(double num1, double num2, double num3) => (num1 + num2 + num3) / 3;
}
}

View file

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

21
Task2/Task2App/Program.cs Normal file
View file

@ -0,0 +1,21 @@
Console.WriteLine("Вычисление среднего 3-ех чисел");
while (true)
{
double[] userNumbers = new double[3];
for (int i = 0; i < 3; i++)
{
Console.Write($"Введите {i + 1} число: ");
string? input = Console.ReadLine();
bool isInputNumeric = double.TryParse(input, out userNumbers[i]);
if (!isInputNumeric)
{
Console.WriteLine($"Ошибка: '{input}' не является числом");
i--;
}
}
double result = Task2Lib.Calculations.AverageOf3(userNumbers[0], userNumbers[1], userNumbers[2]);
Console.WriteLine($"Результат вычислений: {result}");
Console.WriteLine();
}

View file

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Task2\Task2Lib.csproj" />
</ItemGroup>
</Project>