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. double area_of(Point p1, Point p2) {
  16. double width = fabs(p2.x - p1.x);
  17. double height = fabs(p2.y - p1.y);
  18. return width * height;
  19. }
  20.  
  21. double circumference_of(Point p1, Point p2) {
  22. double width = fabs(p2.x - p1.x);
  23. double height = fabs(p2.y - p1.y);
  24. return (width + height) * 2.0;
  25. }
  26.  
  27. int main(void) {
  28. Point p1, p2;
  29.  
  30. printf("左上隅と右下隅の座標を入力してください。\n");
  31.  
  32. printf("座標1");
  33. p1 = scan_point();
  34.  
  35. printf("座標2");
  36. p2 = scan_point();
  37.  
  38. double area = area_of(p1, p2);
  39. double circ = circumference_of(p1, p2);
  40.  
  41. printf("座標1(%.2f, %.2f)\n", p1.x, p1.y);
  42. printf("座標2(%.2f, %.2f)\n", p2.x, p2.y);
  43. printf("面積:%.2f\n", area);
  44. printf("周囲の長さ:%.2f\n", circ);
  45.  
  46. return 0;
  47. }
Success #stdin #stdout 0.01s 5288KB
stdin
0.00 0.00
1.00 1.00
stdout
左上隅と右下隅の座標を入力してください。
座標1座標2座標1(0.00, 0.00)
座標2(1.00, 1.00)
面積:1.00
周囲の長さ:4.00