Advertisement
veselka_a

PointInCircleAndRectangle

Nov 17th, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | None | 0 0
  1. using System;
  2.  
  3. namespace PointInCercleAndRectangle
  4. {
  5.     class PointInCercleRectangle
  6.     {
  7.         static void Main()
  8.         {  //Напишете програма, която проверява дали дадена точка, с кординати (х,у) се намира във вътрешността на окръжност с център (0, 0)
  9.             // и радиус 5 и в същото време вътре в правоъгълник с кординати (-1, 2) (5, 5).
  10.             //Кординатите на правоъгълника са съответно: долен ляв и горен десен ъгъл.
  11.             bool inCircle, inRectangle;
  12.             Console.Write("Enter a value for x: ");
  13.             double x = double.Parse(Console.ReadLine());
  14.  
  15.             Console.Write("Enter a value for y: ");
  16.             double y = double.Parse(Console.ReadLine());
  17.  
  18.             inCircle = (Math.Sqrt(x * x + y * y)) <= 5; // check if x,y are within the circle
  19.  
  20.             inRectangle = ((-1 <= x) && (x <= 5)) && ((2 <= y) && (y <= 5)); // check if x,y are within the rectangle
  21.             bool inCircleAndRectangle = inCircle && inRectangle; // chek if x,y are within the rectangle and circle
  22.             Console.WriteLine("The point with coortinats ({0};{1}) is within the circle and the rectangle? (true/false):{2}",x,y,inCircleAndRectangle) ;
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement