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(void)
  11. {
  12. struct Coordinate a = {1, 5, 2};
  13. struct Coordinate b = {5, 3, 1};
  14. struct Coordinate c = {2, 8, 4};
  15.  
  16. double length_ab;
  17. double length_co;
  18.  
  19. length_ab = sqrt((b.x - a.x)*(b.x - a.x) + (b.y - a.y)*(b.y - a.y) + (b.z - a.z)*(b.z - a.z));
  20.  
  21. length_co = sqrt(c.x*c.x + c.y*c.y + c.z*c.z);
  22.  
  23. if (length_ab > length_co){
  24. printf("length ab : %lf\n", length_ab);
  25. }
  26. else{
  27. printf("length co : %lf\n", length_co);
  28. }
  29.  
  30. return 0;
  31. }
  32.  
  33.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
length co : 9.165151