fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. typedef struct {
  5. double x;
  6. double y;
  7. } Point;
  8.  
  9. Point scan_point(void) {
  10. Point p;
  11. scanf("%lf %lf", &p.x, &p.y);
  12. return p;
  13. }
  14.  
  15.  
  16. double area_of(Point p1, Point p2) {
  17. double width = fabs(p2.x - p1.x);
  18. double height = fabs(p1.y - p2.y);
  19. return width * height;
  20. }
  21.  
  22. double circumference_of(Point p1, Point p2) {
  23. double width = fabs(p2.x - p1.x);
  24. double height = fabs(p1.y - p2.y);
  25. return 2 * (width + height);
  26. }
  27.  
  28. int main(void) {
  29. Point p1, p2;
  30. double area, circumference;
  31.  
  32.  
  33. p1 = scan_point();
  34. p2 = scan_point();
  35.  
  36. area = area_of(p1, p2);
  37. circumference = circumference_of(p1, p2);
  38.  
  39.  
  40. printf("左上隅(%.2f, %.2f), 右下隅(%.2f, %.2f)\n", p1.x, p1.y, p2.x, p2.y);
  41. printf("面積 = %.2f\n", area);
  42. printf("周囲の長さ = %.2f\n", circumference);
  43.  
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0s 5296KB
stdin
1 2
3 4
stdout
左上隅(1.00, 2.00), 右下隅(3.00, 4.00)
面積 = 4.00
周囲の長さ = 8.00