lmarkov

Point In Circle

Nov 26th, 2012
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.33 KB | None | 0 0
  1. using System;
  2.  
  3. class PointInCircle
  4. {
  5.     static void Main()
  6.     {
  7.         double pointCoordinateX, pointCoordinateY;
  8.         int circleRadius = 5;
  9.         string checkResult, quadrant;
  10.         string error01 = "Invalid input! Please enter a number between " + double.MinValue + " and " + double.MaxValue +"\n";
  11.  
  12.         Console.WriteLine("Enter coordinates of the point which you want to check for K((0,0),{0})", circleRadius);
  13.  
  14.         Console.Write("X: ");
  15.         if (double.TryParse(Console.ReadLine(), out pointCoordinateX) && pointCoordinateX > double.MinValue && pointCoordinateX <= double.MaxValue)
  16.         {
  17.             Console.Write("Y: ");
  18.             if (double.TryParse(Console.ReadLine(), out pointCoordinateY) && pointCoordinateY > double.MinValue && pointCoordinateY <= double.MaxValue)
  19.             {
  20.                 if (Math.Sqrt(Math.Pow(pointCoordinateX, 2) + Math.Pow(pointCoordinateY, 2)) <= circleRadius)
  21.                 {
  22.                     checkResult = "inside";
  23.                 }
  24.                 else
  25.                 {
  26.                     checkResult = "outside";
  27.                 }
  28.  
  29.                 if (pointCoordinateX > 0 && pointCoordinateY > 0)
  30.                 {
  31.                     quadrant = "I quadrant";
  32.                 }
  33.                 else if (pointCoordinateX < 0 && pointCoordinateY > 0)
  34.                 {
  35.                     quadrant = "II quadrant";
  36.                 }
  37.                 else if (pointCoordinateX < 0 && pointCoordinateY < 0)
  38.                 {
  39.                     quadrant = "III quadrant";
  40.                 }
  41.                 else if (pointCoordinateX > 0 && pointCoordinateY < 0)
  42.                 {
  43.                     quadrant = "IV quadrant";
  44.                 }
  45.                 else
  46.                 {
  47.                     quadrant = "the center of the circle";
  48.                 }
  49.  
  50.                 Console.WriteLine("The point P(X,Y) with coordinates P({0},{1}) is {2} the circle and it's located in {3}.\n", pointCoordinateX, pointCoordinateY, checkResult, quadrant);                
  51.  
  52.                 Main();
  53.             }
  54.             else
  55.             {
  56.                 Console.WriteLine("{0}", error01);
  57.                 Main();
  58.             }
  59.         }
  60.         else
  61.         {
  62.             Console.WriteLine("{0}", error01);
  63.             Main();
  64.         }        
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment