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