Foros aprenderaprogramar.com

Aprender a programar => C, C++, C#, Java, Visual Basic, HTML, PHP, CSS, Javascript, Ajax, Joomla, MySql y más => Mensaje iniciado por: Dimitar Stefanov en 18 de Julio 2016, 20:53

Título: C# Ejemplo trabajar con Punto coordenadas cartesianas cicunferencia o rectángulo
Publicado por: Dimitar Stefanov en 18 de Julio 2016, 20:53
Ejercicio:

Citar
Write a program that reads a pair of coordinates x and y and uses an expression to checks for given point (x, y) if it is within the circle K({1, 1}, 1.5) and out of the rectangle R(top=1, left=-1, width=6, height=2).

El código:

Código: [Seleccionar]
using System;

class Program {
static void Main() {
float x;
float y;
float radio = 1.5f;
Console.Write("Introduce la X: ");
x = float.Parse(Console.ReadLine());
Console.Write("Introduce la Y: ");
y = float.Parse(Console.ReadLine());

Console.WriteLine();

if(Math.Sqrt((Math.Pow((x-1),2))+(Math.Pow((y-1),2)))<=radio){
Console.Write("Circulo: Entra, ");
}else {
Console.Write("Circulo: NO entra, ");
}

if(x < -1 || x > 5 && y < -1 || y > 1) {
Console.Write("Rectángulo: NO entra");
}else {
Console.Write("Rectángulo: Entra");
}

Console.WriteLine();
}
}

Saludos.