Описание функций внутри функций - C#
Формулировка задачи:
Как описать одну функцию внутри другой? Чтобы было подобное этому:
procedure A();
procedure B();
begin
end;
begin
end.Решение задачи: «Описание функций внутри функций»
textual
Листинг программы
public static void Circle(int x, int y, int r)
{
void PutPixel(int x, int y)
{
System.Console.SetCursorPosition(x, y);
System.Console.Write(" ");
}
void DrawPoints(int x, int y, int cx, int cy)
{
PutPixel(cx + x, cy + y);
PutPixel(cx + x, cy - y);
PutPixel(cx - x, cy + y);
PutPixel(cx - x, cy - y);
}
int Sqr(double x)
{
return System.Convert.ToInt32(System.Math.Pow(x, 2));
}
int x = 0;
int y = r;
System.Console.BackgroundColor = System.ConsoleColor.Green;
while ((y >= 0) || (x < r))
{
DrawPoints(x, y, cx, cy);
MoveDown = System.Math.Abs(Sqr(r) - Sqr(x) - Sqr(y - 1));
MoveRight = System.Math.Abs(Sqr(r) - Sqr(x + 1) - Sqr(y));
MoveRightDown = System.Math.Abs(Sqr(r) - Sqr(x + 1) - Sqr(y - 1));
if (MoveDown < MoveRight)
{
y -= 1;
if (MoveRightDown < MoveDown) { x += 1; }
}
else
{
x += 1;
if (MoveRightDown < MoveRight) { y -= 1; }
}
}
}