C# :: Aufgabe #34 :: Lösung #7
9 Lösungen

#34
Abstand zweier Punkte
Anfänger - C#
von Dome
- 03.01.2013 um 01:09 Uhr
Schreiben Sie ein Programm, welches den Abstand zweier Punkte berechnet. Zuvor müssen die Koordinaten beider Punkte abgefragt werden.
Konsolenausgabe:
x1:1
y1:1
x2:2
y2:2
1.4142135623730951
#7

von kjaenke (1140 Punkte)
- 08.11.2017 um 10:43 Uhr

using System; namespace Exercise_34 { static class Program { static void Main() { Console.Write("x1: "); var x1 = int.Parse(Console.ReadLine() ?? throw new InvalidOperationException()); Console.Write("y1: "); var y1 = int.Parse(Console.ReadLine() ?? throw new InvalidOperationException()); Console.Write("x2: "); var x2 = int.Parse(Console.ReadLine() ?? throw new InvalidOperationException()); Console.Write("y2: "); var y2 = int.Parse(Console.ReadLine() ?? throw new InvalidOperationException()); Console.WriteLine($"Die Entfernung beträgt {Math.Sqrt(Math.Pow((x2-x1),2)+Math.Pow((y2-y1),2))}"); Console.Read(); } } }
Kommentare:
Für diese Lösung gibt es noch keinen Kommentar
Seite 1 von 0
1