C# :: Aufgabe #34 :: Lösung #6
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
#6

von n.rohde (400 Punkte)
- 25.08.2015 um 16:54 Uhr

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AbstandZweierPunkte { class Program { static void Main(string[] args) { int x1, x2, y1, y2; double abstand; Console.Write("x1: "); x1 = Convert.ToInt32(Console.ReadLine()); Console.Write("y1: "); y1 = Convert.ToInt32(Console.ReadLine()); Console.Write("x2: "); x2 = Convert.ToInt32(Console.ReadLine()); Console.Write("y2: "); y2 = Convert.ToInt32(Console.ReadLine()); abstand = Math.Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); Console.WriteLine("Abstand: "+Convert.ToString(Math.Round(abstand, 2))); Console.Read(); } } }
Kommentare:
Für diese Lösung gibt es noch keinen Kommentar
Seite 1 von 0
1