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. {
  11. Point p;
  12. scanf("%lf %lf", &p.x, &p.y);
  13. return p;
  14. }
  15.  
  16. double area_of(Point p1, Point p2)
  17. {
  18. double width = fabs(p2.x - p1.x);
  19. double height = fabs(p1.y - p2.y);
  20. return width * height;
  21. }
  22.  
  23. double circumference_of(Point p1, Point p2)
  24. {
  25. double width = fabs(p2.x - p1.x);
  26. double height = fabs(p1.y - p2.y);
  27. return 2 * (width + height);
  28. }
  29.  
  30. int main(void)
  31. {
  32. Point p1, p2;
  33.  
  34. printf("左上隅と右下隅の座標を入力してください。\n");
  35.  
  36. printf("左上隅:");
  37. p1 = scan_point();
  38.  
  39. printf("右下隅:");
  40. p2 = scan_point();
  41.  
  42. double area = area_of(p1, p2);
  43. double cir = circumference_of(p1, p2);
  44.  
  45. printf("左上隅:(%.2f, %.2f)\n", p1.x, p1.y);
  46. printf("右下隅:(%.2f, %.2f)\n", p2.x, p2.y);
  47.  
  48. printf("面積:%.2f\n", area);
  49. printf("周囲の長さ:%.2f\n", cir);
  50.  
  51. return 0;
  52. }
  53.  
  54.  
Success #stdin #stdout 0s 5280KB
stdin
3
3
7
8
stdout
左上隅と右下隅の座標を入力してください。
左上隅:右下隅:左上隅:(3.00, 3.00)
右下隅:(7.00, 8.00)
面積:20.00
周囲の長さ:18.00