Advertisement
mzografski

PointInACircle

Mar 15th, 2014
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. /*
  8.  * Write an expression that checks if given point (x,  y) is inside a circle K({0, 0}, 2).
  9.  */
  10.  
  11. class PointInACircle
  12. {
  13.     static void Main()
  14.     {
  15.         int circleRad = 2, centerX = 0, centerY = 0;
  16.         float pointX = 0, pointY = 0;
  17.         bool isInCircle;
  18.  
  19.         Console.WriteLine("Provide point X coordinate:");
  20.         while (!float.TryParse(Console.ReadLine(), out pointX))
  21.         {
  22.             Console.WriteLine("Please, enter valid integer.");
  23.         }
  24.         Console.WriteLine("Provide point Y coordinate:");
  25.         while (!float.TryParse(Console.ReadLine(), out pointY))
  26.         {
  27.             Console.WriteLine("Please, enter valid integer.");
  28.         }
  29.        
  30.         isInCircle = (Math.Pow((pointX - centerX),2)+Math.Pow((pointY - centerY),2)) <= Math.Pow(circleRad,2);
  31.  
  32.         Console.WriteLine("\nProvided point with coords ({0};{1}) is {2}", pointX, pointY,isInCircle?"inside the circle." : "outside the circle.\n");
  33.         Console.WriteLine("Press any key to exit.");
  34.         Console.ReadKey();
  35.  
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement