Попадание точки в заштрихованную область исправить ошибку - C#
Формулировка задачи:
Задание:
Написать программу которая по введенному значению аргумента вычисляет значение функции, заданной в виде графика. Параметр R вводится с клавиатуры.Сам график
Вот такой вод код.using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace лаба2_в1_зд_1
{
class Program
{
static void Main(string[] args)
{
double y,x,R;
Console.WriteLine("Введите радиус R ");
R = double.Parse(Console.ReadLine());
Console.WriteLine("Введите кординату X");
x = double.Parse(Console.ReadLine());
if ((x < -9) || (x > 9))
{
Console.WriteLine("Значение функции не определено!");
Console.ReadKey();
}
else
{
if ((x >= -9) && (x <= -6))
{
y = -Math.Sqrt(Math.Pow(R, 2) - Math.Pow(x + 6, 2));
}
else if ((x > -6) && (x <= -3))
{
y = x + 3;
}
else if ((x > -3) && (x <= 0))
{
y = Math.Sqrt(Math.Pow(R, 2) - Math.Pow(x, 2));
}
else if ((x > 0) && (x <= 3))
{
y = 3 - x;
}
else if ((x > 3) && (x <= 9))
{
y = 0.5 * (x - 3);
}
Console.WriteLine("y = ", y);
Console.ReadKey();
}
}
}
}Решение задачи: «Попадание точки в заштрихованную область исправить ошибку»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace лаба2_в1_зд_1
{
class Program
{
static void Main(string[] args)
{
double y, x, R;
y = 0;
R = 3;
Console.WriteLine("Введите кординату X");
x = Convert.ToDouble(Console.ReadLine());
if (x >= -9 & x <= -6)
{
y = -Math.Sqrt(Math.Pow(R, 2) - Math.Pow(x + 6, 2));
}
else if (x >= -6 & x <= -3)
{
y = x + 3;
}
else if (x >= -3 & x <= 0)
{
y = Math.Sqrt(Math.Pow(R, 2) - Math.Pow(x, 2));
}
else if (x >= 0 & x <= 3)
{
y = 3 - x;
}
else if(x >= 3 & x <= 9)
{
y = 0.5 * (x - 3);
}
else
{
Console.WriteLine("Значение функции не определено!");
}
{
Console.WriteLine("y = " + y);
Console.ReadKey();
}
}
}
}