fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. typedef struct {
  5. double x;
  6. double y;
  7. } Point;
  8.  
  9. double area_of(Point p1, Point p2);
  10. double circumference_of(Point p1, Point p2);
  11.  
  12. int main(void) {
  13. Point p1, p2;
  14.  
  15. scanf("%lf, %lf", &p1.x, &p1.y);
  16.  
  17. scanf("%lf, %lf", &p2.x, &p2.y);
  18.  
  19. printf("座標1(%.2f, %.2f)\n", p1.x, p1.y);
  20. printf("座標2(%.2f, %.2f)\n", p2.x, p2.y);
  21.  
  22. printf("面積: %.2f\n", area_of(p1, p2));
  23. printf("周囲の長さ: %.2f\n", circumference_of(p1, p2));
  24.  
  25. return 0;
  26. }
  27.  
  28. double area_of(Point p1, Point p2) {
  29. double width = fabs(p1.x - p2.x);
  30. double height = fabs(p1.y - p2.y);
  31. return width * height;
  32. }
  33.  
  34. double circumference_of(Point p1, Point p2) {
  35. double width = fabs(p1.x - p2.x);
  36. double height = fabs(p1.y - p2.y);
  37. return (width + height) * 2.0;
  38. }
  39.  
Success #stdin #stdout 0.01s 5280KB
stdin
3,2
stdout
座標1(3.00, 2.00)
座標2(0.00, 0.00)
面積: 6.00
周囲の長さ: 10.00