The Circle – Simple C# Math

Created by
Wednesday, August 3, 2016

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.

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();
 
        }
    }

 

Tags:
c#
math
0
Rating
1 2 3 4 5

Save

Saved

Report

Reported
Reasons
Cancel
0 comments