fork download
  1. #include<math.h>
  2.  
  3. struct Coordinate{
  4. double x;
  5. double y;
  6. double z;
  7. };
  8.  
  9. int main(void)
  10. {
  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;
  16. double length_co;
  17.  
  18. 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) );
  19. length_co = sqrt( c.x*c.x + c.y*c.y + c.z*c.z );
  20.  
  21. if(length_ab > length_co){
  22. printf("length ab : %lf\n", length_ab );
  23. }
  24. else{
  25. printf("length co : %lf\n", length_co );
  26. }
  27.  
  28. return 0;
  29. }
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
Success #stdin #stdout 0s 5300KB
stdin
Standard input is empty
stdout
length co : 9.165151