Advertisement
GogoK

Point in a Circle

Feb 16th, 2015
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. using System;
  2.  
  3. class PointInCircle
  4. {
  5.     static void Main()
  6.     {
  7.         double x = 0;
  8.         double y = 0;
  9.         double radius = 2;
  10.  
  11.         double[] arrayX = { 0, -2, -1, 1.5, -1.5, 100, 0,  0.2,   0.9, 1 };
  12.         double[] arrayY = { 1,  0,  2,  -1, -1.5, -30, 0, -0.8, -1.93, 1.655 };
  13.  
  14.         string tab = new string('\t', 1);
  15.         string table = new string('-', 45);
  16.  
  17.         Console.WriteLine("inSide" + tab + tab + "X" + tab + "Y" + tab + "Vector Length     \r\n" + table);
  18.  
  19.         int count = 0;
  20.         while (count < arrayX.Length)
  21.         {
  22.             double vector = Math.Sqrt((Math.Pow(x - (arrayX[count]), 2)) + (Math.Pow(y - (arrayY[count]), 2)));
  23.  
  24.             if (vector > radius)
  25.             {
  26.                 Console.WriteLine(false + tab + tab + "{0}" + tab + "{1}" + tab + "{2:0.###}", arrayX[count], arrayY[count], vector);
  27.             }
  28.             else if (vector <= radius)
  29.             {
  30.                 Console.WriteLine(true + tab + tab + "{0}" + tab + "{1}" + tab + "{2:0.###}", arrayX[count], arrayY[count], vector);
  31.             }
  32.             count++;
  33.         }
  34.         Console.WriteLine(table);
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement