« en: 18 de Julio 2016, 20:48 »
Ejercicio:
Write a program that reads the coordinates of a point x and y and using an expression checks if given point (x, y) is inside a circle K({0, 0}, 2) - the center has coordinates (0, 0) and the circle has radius 2. The program should then print "yes DISTANCE" if the point is inside the circle or "no DISTANCE" if the point is outside the circle.
In place of DISTANCE print the distance from the beginning of the coordinate system - (0, 0) - to the given point.
El código:
using System;
class Program {
static void Main(){
float x;
float y;
float radio = 2.0f;
Console.Write("Introduce la X: ");
x = float.Parse(Console.ReadLine());
Console.Write("Introduce la Y: ");
y = float.Parse(Console.ReadLine());
if(Math.Sqrt((Math.Pow((x-0),2))+(Math.Pow((y-0),2)))<=radio){
Console.WriteLine("Entra, distancia: "+ (Math.Sqrt(Math.Pow((x-0), 2) + Math.Pow((y-0), 2))).ToString("f2"));
}else {
Console.WriteLine("NO entra, distancia: " + (Math.Sqrt(Math.Pow((x-0), 2) + Math.Pow((y-0), 2))).ToString("f2"));
}
}
}
Saludos.
« Última modificación: 20 de Julio 2016, 12:37 por César Krall »

En línea