## The Circle – Simple C# Math

Today we are going to write a simple console application that takes in values that we give and determines whether or not the points we input lie inside the circle, on the circle or outside the circle.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
class Program { static void Main(string[] args) { /* * Equation of the circle (x‐a) ^2 + (y‐b) ^2 = r^2 */ Console.WriteLine("www.dotnetdevelopernetwork.com"); int x; int y; int radius; int radius_square; int coordinates_calc; Console.WriteLine("Enter X Coordinates: "); x = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter Y Coordinates: "); y = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Etner Radius of the Circle: "); radius = Convert.ToInt32(Console.ReadLine()); radius_square = radius * radius; coordinates_calc = (x * x) + (y * y); if (coordinates_calc == radius_square) { Console.WriteLine("Points lie on the circle."); } else if (coordinates_calc > radius_square) { Console.WriteLine("Points lie outside the circle."); } if (coordinates_calc < radius_square) { Console.WriteLine("Points lie inside the circle."); } Console.ReadKey(); } } |