C++ :: Aufgabe #28 :: Lösung #5
5 Lösungen
#28
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
#5
von basic (1310 Punkte)
- 21.10.2020 um 00:39 Uhr
#include <iostream>
#include <cmath>
using namespace std;
struct Point {
float x;
float y;
};
int main() {
Point p1, p2;
cout << "x1: ";
cin >> p1.x;
cout << "y1: ";
cin >> p1.y;
cout << "x2: ";
cin >> p2.x;
cout << "y2: ";
cin >> p2.y;
cout << "\nAbstand: " << sqrt(pow(p2.x - p1.x, 2) + pow(p2.y - p1.y, 2)) << "\n";
}Kommentare:
Für diese Lösung gibt es noch keinen Kommentar
Seite 1 von 0
1
