Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class PointInCircle
- {
- static void Main()
- {
- double pointCoordinateX, pointCoordinateY;
- int circleRadius = 5;
- string checkResult, quadrant;
- string error01 = "Invalid input! Please enter a number between " + double.MinValue + " and " + double.MaxValue +"\n";
- Console.WriteLine("Enter coordinates of the point which you want to check for K((0,0),{0})", circleRadius);
- Console.Write("X: ");
- if (double.TryParse(Console.ReadLine(), out pointCoordinateX) && pointCoordinateX > double.MinValue && pointCoordinateX <= double.MaxValue)
- {
- Console.Write("Y: ");
- if (double.TryParse(Console.ReadLine(), out pointCoordinateY) && pointCoordinateY > double.MinValue && pointCoordinateY <= double.MaxValue)
- {
- if (Math.Sqrt(Math.Pow(pointCoordinateX, 2) + Math.Pow(pointCoordinateY, 2)) <= circleRadius)
- {
- checkResult = "inside";
- }
- else
- {
- checkResult = "outside";
- }
- if (pointCoordinateX > 0 && pointCoordinateY > 0)
- {
- quadrant = "I quadrant";
- }
- else if (pointCoordinateX < 0 && pointCoordinateY > 0)
- {
- quadrant = "II quadrant";
- }
- else if (pointCoordinateX < 0 && pointCoordinateY < 0)
- {
- quadrant = "III quadrant";
- }
- else if (pointCoordinateX > 0 && pointCoordinateY < 0)
- {
- quadrant = "IV quadrant";
- }
- else
- {
- quadrant = "the center of the circle";
- }
- 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);
- Main();
- }
- else
- {
- Console.WriteLine("{0}", error01);
- Main();
- }
- }
- else
- {
- Console.WriteLine("{0}", error01);
- Main();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment