Advertisement
Martichka

Operators and Expressions task 9

Nov 27th, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. using System;
  2. class CircleAndRectangle
  3. {
  4.     static void Main()
  5.     {
  6.         Console.WriteLine("Enter X & Y coordinates that have to be in the circle K((1,1)3)\r\nand out of the rectangle R(top=1; left= -1; width = 6; heigh = 2):");
  7.         Console.Write("x = ");
  8.         string first = Console.ReadLine();
  9.         int x = int.Parse(first);
  10.         Console.Write("y = ");
  11.         string second = Console.ReadLine();
  12.         int y = int.Parse(second);
  13.         int cirleRadius = 3;
  14.         bool inCircle = (x * x + y * y <= cirleRadius * cirleRadius);
  15.         bool rx = (x >= (-1)) && (x <= 5);
  16.         bool ry = (y>=(-1)) && (y<=1);
  17.         bool inRectangle = (rx == true) && (ry == true);
  18.         bool outRectangle = (rx ==true) || (ry==true);
  19.  
  20.         if (((inCircle == true) && (inRectangle == true)) || (outRectangle == false))
  21.         {
  22.             Console.WriteLine("Coordinates that you entered are not valide!");
  23.         }
  24.         else if ((inCircle == true) && (outRectangle == true))
  25.         {
  26.             Console.WriteLine("ok");
  27.         }
  28.         else
  29.         {
  30.             Console.WriteLine("Error!");
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement