fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3. struct Coordinate {
  4. double x;
  5. double y;
  6. double z;
  7. };
  8.  
  9. int main() {
  10.  
  11. struct Coordinate A = {1.0, 5.0, 2.0};
  12. struct Coordinate B = {5.0, 3.0, 1.0};
  13. struct Coordinate C = {2.0, 8.0, 4.0};
  14. struct Coordinate origin = {0.0, 0.0, 0.0};
  15.  
  16. double distAB, distCO;
  17.  
  18.  
  19. distAB = sqrt(pow(B.x - A.x, 2) + pow(B.y - A.y, 2) + pow(B.z - A.z, 2));
  20.  
  21.  
  22. distCO = sqrt(pow(C.x - origin.x, 2) + pow(C.y - origin.y, 2) + pow(C.z - origin.z, 2));
  23.  
  24.  
  25. printf("点A-B間の距離: %f\n", distAB);
  26. printf("点C-原点間の距離: %f\n", distCO);
  27.  
  28. if (distAB > distCO) {
  29. printf("長い方の距離は 点A-B間 で、値は %f です。\n", distAB);
  30. } else {
  31. printf("長い方の距離は 点C-原点間 で、値は %f です。\n", distCO);
  32. }
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
点A-B間の距離: 4.582576
点C-原点間の距離: 9.165151
長い方の距離は 点C-原点間 で、値は 9.165151 です。