fbinnzhivko

03.02 Disk

Apr 15th, 2016
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1. using System;
  2.  
  3. class Disk
  4. {
  5.     static void Main()
  6.     {
  7.         int fieldSize = int.Parse(Console.ReadLine());
  8.         int radius = int.Parse(Console.ReadLine());
  9.         int diskCenterRow = fieldSize/2;
  10.         int diskCenterCol = fieldSize / 2;
  11.  
  12.         for (int currentRow = 0; currentRow < fieldSize; currentRow++)
  13.         {
  14.             for (int currentCol = 0; currentCol < fieldSize; currentCol++)
  15.             {
  16.                 int deltaX = currentCol - diskCenterCol,
  17.                     deltaY = currentRow - diskCenterRow;
  18.  
  19.                 double distanceToCenter = Math.Sqrt(deltaX * deltaX + deltaY * deltaY);
  20.                 bool isWithinDisk = distanceToCenter <= radius;
  21.  
  22.                 if (isWithinDisk)
  23.                 {
  24.                     Console.Write('*');
  25.                 }
  26.                 else
  27.                 {
  28.                     Console.Write('.');
  29.                 }
  30.             }
  31.             Console.WriteLine();
  32.         }
  33.     }
  34. }
Add Comment
Please, Sign In to add comment