Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- //Distancia entre 2 puntos con Estructura
- struct Punto{
- float x;
- float y;
- Punto(){x = 0; y = 0;} //Constructor
- void Set(float xo, float yo){x = xo; y = yo;} //Estableciendo valor
- };
- typedef struct Punto Punto;
- //Función Prototipo:
- float distancia(Punto, Punto);
- int main()
- {
- Punto punto1, punto2; // se inician como 0, 0 por el constructor
- //Establecemos 2 puntos:
- punto1.Set(4.6, 8.4);
- punto2.Set(-6.3, 2.5);
- //Escribimos distancia
- cout << endl << "La distancia es: " << distancia(punto1, punto2) << endl;
- return 0;
- }
- float distancia(Punto p1, Punto p2){
- return sqrt(pow(p1.x - p2.x, 2.0) + pow(p1.y - p2.y, 2.0));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement