JosepRivaille

P46254: Distància entre dos punts

May 7th, 2015
1,990
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. struct Punt {
  6.     double x, y;
  7. };
  8.  
  9. void llegeix_punt(Punt& n) {
  10.     cin >> n.x >> n.y;
  11. }
  12.  
  13. double distancia(const Punt& a, const Punt& b) {
  14.     double de;
  15.     de = (b.x - a.x)*(b.x - a.x) + (b.y  - a.y)*(b.y - a.y);
  16.     de = sqrt(de);
  17.     return de;
  18. }
  19.  
  20. int main () {
  21.     Punt a, b;
  22.     llegeix_punt(a);
  23.     llegeix_punt(b);
  24.     cout << distancia(a, b) << endl;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment