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.  
  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.0 * (width + height);
  28. }
  29.  
  30. int main(void) {
  31. printf("左上隅と右下隅の座標を入力\n");
  32.  
  33. Point p1 = scan_point();
  34. Point p2 = scan_point();
  35.  
  36. printf("座標1(%.2f, %.2f)\n", p1.x, p1.y);
  37. printf("座標2(%.2f, %.2f)\n", p2.x, p2.y);
  38.  
  39. double area = area_of(p1, p2);
  40. double circ = circumference_of(p1, p2);
  41.  
  42. printf("面積 : %.2f\n", area);
  43. printf("周囲の長さ : %.2f\n", circ);
  44.  
  45. return 0;
  46. }
Success #stdin #stdout 0s 5316KB
stdin
0 0 1 1
stdout
左上隅と右下隅の座標を入力
座標1(0.00, 0.00)
座標2(1.00, 1.00)
面積 : 1.00
周囲の長さ : 4.00