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. length_co = sqrt( c.x*c.x + c.y*c.y + c.z*c.z );
  21.  
  22. if(length_ab > length_co){
  23. printf("length ab : %lf\n", length_ab );
  24. }
  25. else{
  26. printf("length co : %lf\n", length_co );
  27. }
  28.  
  29. return 0;
  30. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
length co : 9.165151