fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. struct Coordinate {
  5. double x;
  6. double y;
  7. double z;
  8. };
  9.  
  10. int main() {
  11. struct Coordinate a = {1, 5, 2};
  12. struct Coordinate b = {5, 3, 1};
  13. struct Coordinate c = {2, 8, 4};
  14.  
  15. double length_ab = sqrt((b.x - a.x)*(b.x - a.x) +
  16. (b.y - a.y)*(b.y - a.y) +
  17. (b.z - a.z)*(b.z - a.z));
  18.  
  19. double length_co = sqrt(c.x*c.x + c.y*c.y + c.z*c.z);
  20.  
  21. printf("Length AB: %f\n", length_ab);
  22. printf("Length CO: %f\n", length_co);
  23.  
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0.01s 5324KB
stdin
Standard input is empty
stdout
Length AB: 4.582576
Length CO: 9.165151