Advertisement
AnitaN

03.OperatorsExpressionsStatements/07.PointInCircle

Mar 20th, 2014
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. //Problem 7.    Point in a Circle
  2. //Write an expression that checks if given point (x,  y) is inside a circle K({0, 0}, 2).
  3.  
  4. using System;
  5.  
  6. class PointInCircle
  7. {
  8.     static void Main()
  9.     {
  10.         Console.WriteLine("Is point (x,y) inside a circle K((0,0),2) ? ");
  11.         //Enter x
  12.         Console.Write("Please, Enter point(x,y):  x=");
  13.         double x = double.Parse(Console.ReadLine());
  14.         //Enter y
  15.         Console.Write("Please, Enter point(x,y):  y=");
  16.         double y = double.Parse(Console.ReadLine());
  17.         int radiusCircle = 2;
  18.         //Calculate the distance from center of circle(0,0) to the point(x,y)
  19.         double pointDistance = Math.Sqrt((x*x)+(y*y));
  20.         //Check the point(x,y)
  21.         bool checkPoint=(pointDistance <= radiusCircle);
  22.         if (checkPoint)
  23.         {
  24.             Console.WriteLine("{0}.The Point({1},{2}) is inside a circle K((0,0),2).",checkPoint,x,y);
  25.         }
  26.         else
  27.         {
  28.             Console.WriteLine("{0}.The Point({1},{2}) is outside a circle K((0,0),2).",checkPoint, x, y);
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement